View Full Version : php mysql help ?
teksigns
04-16-2004, 03:45 AM
i have a table called
color_guide
it has several fields in it ....
one of them is
name
what php mysql statement would i need to use to retrieve
the "name" that has the most rows along with how many it has.....
example :
if john posted the most with 28 post i want to be able to print
John : 28
since hes the top poster......
help !
teksigns
04-16-2004, 03:23 PM
Use PHP's built-in functions (mysql_connect(), mysql_select_db() and mysql_query() (see http://www.php.net)), and this as your query:
select count(*) from color_guide where name='john';
will not work ......
heres the problem
the script does not know who is the highest .......
thats what i want to find out
i want to know who is te highest by the amount of times there name is in new rows .
and what the count of rows for the highest poster is ......
Dean C
04-16-2004, 03:32 PM
Use MAX instead of COUNT IIRC
teksigns
04-16-2004, 03:34 PM
Use MAX instead of COUNT IIRC
do you have a example
teksigns
04-16-2004, 03:41 PM
here is a example database.
i have a table named
color_guide
with the following fields and data.
-------------------------------------------------
| poster | color | info | more info |
-------------------------------------------------
| john | blue | xx | xx |
| joe | black | xx | xx |
| chris | red | xx | xx |
| john | yellow | xx | xx |
| joe | xxxx | xx | xx |
| john | xxxx | xx | xx |
-------------------------------------------------
so in my sample database i need a query that will
check who has the most rows and display the count .
example :
John has 3 post
my username
04-16-2004, 03:47 PM
Ok, i saw that i answered wrong question (read a little too fast) and deleted my post.
You were too quick for me...
Ok...I believe you may do it like this with mySQL:
(I've been working for 9 hours now, so it might not work :D)
SELECT name, count(name) AS number FROM color_guide GROUP BY name ORDER BY number DESC LIMIT 1;
Then you extract name and number from your result.
Example:
$result = mysql_fetch_object(mysql_query($query, $dblink), MYSQL_ASSOC);
$highest = $result->name;
$number = $result->number;
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.