Although i'm not a newbie to PHP i'm rather new to MySQL and am ashamed to admit i've got myself stuck. I'm building a rating system for sites, here's the code to read data from the db
//Load the ratings into an array
for($i = 1; $i <= 2; $i++)
{
$result = mysql_query("SELECT * FROM dtable WHERE id=$i",$db);
$myrow = mysql_fetch_array($result);
$order[$i] = $myrow["rank"];
}
//Sort the array
sort($order, SORT_NUMERIC);
//Extract info from database using sorted results
for($i = 0; $i < 2; $i++)
{
$result = mysql_query("SELECT * FROM dtable WHERE rank=$order[$i]",$db);
//Put it in array form
$myrow = mysql_fetch_array($result);
//Place info in variables
$name = $myrow['name'];
$desc = $myrow['description'];
$adby = $myrow['adby'];
$rank = $myrow['rank'];
$id = $myrow['id'];
Now, it works pretty fine but I came upon a bug, if two entries have the same rank it reads one
entry twice! Ofcourse I figured out the problem but I dont know how to solve it, any suggestions?
|