Page 1 of 1

Getting the right values from sql

Posted: Wed Sep 17, 2003 5:50 pm
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?

Posted: Wed Sep 17, 2003 5:57 pm
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.

Posted: Wed Sep 17, 2003 5:58 pm
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?

Posted: Wed Sep 17, 2003 5:58 pm
by JAM

Code: Select all

"select max(views), min(views) from table"

Posted: Wed Sep 17, 2003 5:59 pm
by qads
go with JAM..he had more sleep then rest of us :lol:

Posted: Wed Sep 17, 2003 6:00 pm
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...

Posted: Wed Sep 17, 2003 6:03 pm
by qads
lol, yea, i been up for about 29 hours now...wha?...grandad? is that you? 8O

re

Posted: Wed Sep 17, 2003 6:28 pm
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

Posted: Wed Sep 17, 2003 6:34 pm
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];

Posted: Wed Sep 17, 2003 6:47 pm
by GGK
yeah thats it