[PHP] php with mysql COUNT, DISTINCT syntax, might be a bit 0T
Hi, I have a table where a users details are entered for the products he bought, the only part that is repeated is the order_id, I basically need to only get the order per person, and paginate for all the customers eg: if user tom bought 3 items in the database it would be entered as: order_id item_name 023 soap 023 brush 023 towel So i am trying this: $num_rows = mysql_result(mysql_query(SELECT COUNT(*), DISTINCT(order_number) FROM .$prefix._purchases),0); (the idea being taht $num_rows will give my paginating part of the program the total number of records that match my search.) which gives me the most pretty error of: Warning: mysql_result(): supplied argument is not a valid MySQL result resource in \www\p\admin\show_purc.php on line 9 I''m pretty sure the problem is in my SQL statement, but have had no luck searching and reading in the mysql manual for count with distinct but am pretty sure it can be done as i have not found anything saying the opposite...any ideas? Thanks, -Ryan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php with mysql COUNT, DISTINCT syntax, might be a bit 0T
Try this: SELECT COUNT(*), order_number FROM . $prefix . _purchases GROUP BY order_number as your query. Shaunak - Original Message - From: Ryan A [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, February 09, 2004 8:36 PM Subject: [PHP] php with mysql COUNT, DISTINCT syntax, might be a bit 0T Hi, I have a table where a users details are entered for the products he bought, the only part that is repeated is the order_id, I basically need to only get the order per person, and paginate for all the customers eg: if user tom bought 3 items in the database it would be entered as: order_id item_name 023 soap 023 brush 023 towel So i am trying this: $num_rows = mysql_result(mysql_query(SELECT COUNT(*), DISTINCT(order_number) FROM .$prefix._purchases),0); (the idea being taht $num_rows will give my paginating part of the program the total number of records that match my search.) which gives me the most pretty error of: Warning: mysql_result(): supplied argument is not a valid MySQL result resource in \www\p\admin\show_purc.php on line 9 I''m pretty sure the problem is in my SQL statement, but have had no luck searching and reading in the mysql manual for count with distinct but am pretty sure it can be done as i have not found anything saying the opposite...any ideas? Thanks, -Ryan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php with mysql COUNT, DISTINCT syntax, might be a bit 0T
Hey, Thanks for replying. Nope, that didnt work, but i modified my search terms on google and kept on trying with different search terms and got the solution here: http://dbforums.com/arch/230/2002/11/623223 Cheers, -Ryan On 2/10/2004 3:14:21 AM, Shaunak Kashyap ([EMAIL PROTECTED]) wrote: Try this: SELECT COUNT(*), order_number FROM . $prefix . _purchases GROUP BY order_number as your query. Shaunak - Original Message - From: Ryan A [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, February 09, 2004 8:36 PM Subject: [PHP] php with mysql COUNT, DISTINCT syntax, might be a bit 0T Hi, I have a table where a users details are entered for the products he bought, the only part that is repeated is the order_id, I basically need to only get the order per person, and paginate for all the customers eg: if user tom bought 3 items in the database it would be entered as: order_id item_name 023 soap 023 brush 023 towel So i am trying this: $num_rows = mysql_result(mysql_query(SELECT COUNT(*), DISTINCT(order_number) FROM . $prefix._purchases),0); (the idea being taht $num_rows will give my paginating part of the program the total number of -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php