Getting the right values from sql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GGK
Forum Newbie
Posts: 3
Joined: Wed Sep 17, 2003 5:50 pm

Getting the right values from sql

Post by GGK »

Hi all

I'm working on a rating system
I got 1 problem, i dont know how to do this


i got lets say 400 records with a field "views"
i need the highest "views" from all records and the lowest "views" count

how can i do this?
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

like this

Code: Select all

<?php
$high = mysql_query("select `views` from table order by `views` DESC limit 1");

$low = mysql_query("select `views` from table order by `views` ASC limit 1");

?>
then u can fetch the dataout and do whatever you want to do with it.
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

Uh, repeat that? You need both the value that is highest for "views" and the values that are the lowest? Is that it?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Code: Select all

"select max(views), min(views) from table"
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

go with JAM..he had more sleep then rest of us :lol:
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

qads wrote:go with JAM..he had more sleep then rest of us :D
Haha... Likely as I work shifts ;)

Talk about everyone posting at once...
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

lol, yea, i been up for about 29 hours now...wha?...grandad? is that you? 8O
GGK
Forum Newbie
Posts: 3
Joined: Wed Sep 17, 2003 5:50 pm

re

Post by GGK »

Thanks that what i was looking for
But can i call both of them seperate with this one?

Code: Select all

<?php
"select max(views), min(views) from table"
?>

maybe i beter explain what i try to do

i want to give my games a rating based on the highest en lowest views count
highest is 345 hits
lowest is 0 hits

now i want to output a rating from these 2 counts example lets say i made this in a function and i call it from my view.php?id=53

then it looks up the hit count and compares it with the info in the function

pfff my english is bad, i hope u understand it LOL
Last edited by GGK on Wed Sep 17, 2003 6:40 pm, edited 1 time in total.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

I actually dont know... Nowadays we (at least I) knows these things after browsing the mysql manual more than a couple of times.

http://www.mysql.com/doc/en/Functions.html is something worth bookmarking tho.

You mean like this?

Code: Select all

$result = mysql_fetch_array(mysql_query("select max(views), min(views) from table"));
    $max = $result[0];
    $min = $result[1];
GGK
Forum Newbie
Posts: 3
Joined: Wed Sep 17, 2003 5:50 pm

Post by GGK »

yeah thats it
Post Reply