Copy link to clipboard
Copied
Hello,
I am creating the HTML table below in PHP. I would like to sort it by the value $effective vote in descending order. How do I do that?
Thanks,
John
if(mysql_num_rows($result)>0){
while($table=mysql_fetch_row($result)){
print "<p class=\"topic\">$table[0]</p>\n";
$r=mysql_query("SELECT * FROM `$table[0]`");
print "<table class=\"navbar\">\n";
while($row=mysql_fetch_array($r)){
$effective_vote = $row['votes_up'] - $row['votes_down'];
print "<tr>";
print "<td>".'<a href="http://'.$row['site'].'" class="links2">'.$row['site'].'</a>'."</td>";
print "<td class='votes'>".'<span class="votes_count" id="votes_count'.$row['id'].'">'.number_format($effective_vote).'</span>'."</td>";
print "<td class='ballot'>".'<span class="button" id="button'.$row['id'].'">'.'<a href="javascript:;" class="cell1" id="'.$row['id'].'">'.Vote.'</a>'.'</span>'."</td>";
}
print "</tr>\n";
}
print "</table>\n";
SELECT * , votes_up - votes_down AS effective_vote
FROM `$table[0]`
ORDER BY effective_vote DESC
This also gives you $row['effective_vote'] as part of your database result.
Copy link to clipboard
Copied
SELECT * , votes_up - votes_down AS effective_vote
FROM `$table[0]`
ORDER BY effective_vote DESC
This also gives you $row['effective_vote'] as part of your database result.
Copy link to clipboard
Copied
Thanks David,
It works like a charm!
I appreciate the help.
Regards,
John
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more