help with difficult php/mysql syntax...advice appreciated
Moderator: General Moderators
-
scarface222
- Forum Contributor
- Posts: 354
- Joined: Thu Mar 26, 2009 8:16 pm
help with difficult php/mysql syntax...advice appreciated
Hey guys I am trying to do a mysql select in php and it is probably easy for some but I am not sure how to do it. I want to create a select statement to find out which user is entered in my table the most. How do I approach this?
Last edited by scarface222 on Thu Jul 23, 2009 2:00 pm, edited 1 time in total.
Re: help with difficult php/mysql syntax...advice appreciated
May be you can use group by with having function..
Re: help with difficult php/mysql syntax...advice appreciated
You don't need HAVING. Just COUNT() and GROUP BY. Eg
[sql]SELECT `value`, COUNT(`value`) AS total FROM `table` GROUP BY `value` ORDER BY total DESC LIMIT 1[/sql]
[sql]SELECT `value`, COUNT(`value`) AS total FROM `table` GROUP BY `value` ORDER BY total DESC LIMIT 1[/sql]
-
scarface222
- Forum Contributor
- Posts: 354
- Joined: Thu Mar 26, 2009 8:16 pm
Re: help with difficult php/mysql syntax...advice appreciated
Thanks for the reply. I wanted to see which user was entered in the database the most so I tried your suggestion
I just get error select query failed. Does anyone else know how to do this and how do you echo the result (the most entered user) when finished?
Code: Select all
$query="SELECT 'user', COUNT('user') AS total FROM 'data' GROUP BY 'user' ORDER BY total DESC LIMIT";
$result=mysql_query($query) or die('Error, select query failed');-
scarface222
- Forum Contributor
- Posts: 354
- Joined: Thu Mar 26, 2009 8:16 pm
Re: help with difficult php/mysql syntax...advice appreciated
Also I almost forgot I just want to display 3 entries anyone have an idea I can't find an answer for this. Thanks in advance for any help...
Re: help with difficult php/mysql syntax...advice appreciated
You copied the query incorrectly. The syntax is not valid.
-
scarface222
- Forum Contributor
- Posts: 354
- Joined: Thu Mar 26, 2009 8:16 pm
Re: help with difficult php/mysql syntax...advice appreciated
k I figured out the syntax and the echo statement, sorry I was being an idiot lol thanks for your help guys