Re: php with mysql COUNT, DISTINCT syntax, might be a bit 0T

From: Date: Tue, 10 Feb 2004 02:14:21 +0000
Subject: Re: php with mysql COUNT, DISTINCT syntax, might be a bit 0T
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-177245@lists.php.net to get a copy of this message
Try this: "SELECT COUNT(*), order_number FROM " . $prefix . "_purchases GROUP BY order_number" as your query. Shaunak ----- Original Message ----- From: "Ryan A" <ryan@coinpass.com> To: <php-general@lists.php.net> 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 > 0000023 soap > 0000023 brush > 0000023 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 >

« previous php.general (#177245) next »