Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PHP - Sorting a Table in Descending Order

Guest
May 14, 2009 May 14, 2009

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";

TOPICS
Server side applications
691
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 15, 2009 May 15, 2009

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.

Translate
LEGEND ,
May 15, 2009 May 15, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 15, 2009 May 15, 2009
LATEST

Thanks David,

It works like a charm!

I appreciate the help.

Regards,

John

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines