This is a discussion on "Highest Values" within the PHP Forum section. This forum, and the thread "Highest Values are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Highest Values
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
Highest Values
Hi can anyone tell me how to display the top 3 fields from a MySQL database in order of highest number
I have a voting system like so: id---total_votes---total_value 1 -------- 3 -------- 23 2 -------- 2 -------- 42 3 -------- 6 -------- 10 4 -------- 2 -------- 9 5 -------- 1 -------- 11 I want it to display the top 3 total_value fields which in this case would be: ID 2, 3 and 5 Can anyone help? Thanks Robert |
|
|
|
#2
|
|||
|
|||
|
Re: Highest Values
The main MySQL command you need is
select total_value from whatevertablescalled order by total_value desc limit 3 I see you've posted this in the PHP forum - are you happy with the fucntion calls to conenct to the database and bring the result set back, or did you want guidance on that area as well? |
|
#3
|
|||
|
|||
|
Re: Highest Values
Hi thanks for your help.
No its ok i know how to connect to the database, Can u give me the exact code to do this i have to get it done as soon as possible. Ive tried the code below but it just prints out the query in match.
Much appreciated thanks Robert Last edited by robukni; May 4th, 2007 at 09:01. |
|
#4
|
|||
|
|||
|
Re: Highest Values
Replace echo($match) with ...
$rs = mysql_query($match); while ($row = mysql_fetch_assoc($rs)) { echo ($row["total_value"]); } You need to run the query against the database, read it back row by row, and print out the result. |
|
#5
|
|||
|
|||
|
Re: Highest Values
Hi ok i have tried that and the code now looks like so:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/kidzglob/public_html/coverart/covers_content.php on line 126 Thanks Robert |
|
#6
|
|||
|
|||
|
Re: Highest Values
Its ok got it working
Thanks Robert |
|
#7
|
|||
|
|||
|
Re: Highest Values
By adding back in the $match = line??
|
![]() |
| Tags |
| help |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What can I use to make something update automatically (people with the highest scores | imagehorizons | PHP Forum | 1 | May 18th, 2008 16:16 |
| Help please : Can't get the highest number to be recognised | madmaxusm | JavaScript Forum | 0 | May 28th, 2007 09:16 |
| Setting Form Values to Previously Entered Values | masonbarge | PHP Forum | 6 | Oct 17th, 2006 17:36 |
| determine which variable has the highest value... | tehrobot | Flash & Multimedia Forum | 2 | Oct 16th, 2006 02:33 |
| Assign string values to integer values of a session variable | Andy K | Classic ASP | 1 | Jul 13th, 2005 08:29 |