ORDER BY variable DESC

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ArizonaJohn
    New Member
    • May 2009
    • 21

    ORDER BY variable DESC

    Hello,

    I would like the code below to sort the echoed output by votes_up descending. I have added "ORDER BY votes_up DESC" to both queries, but the echoed output is still not sorting. Any ideas why it is not working?

    Thanks in advance,

    John

    Code:
    $result = mysql_query("SHOW TABLES FROM feather") 
    or die(mysql_error()); 
     
    while(list($table)= mysql_fetch_row($result))
    {
      $sqlA = "SELECT COUNT(*) FROM `$table` WHERE `site` LIKE '$entry' ORDER BY votes_up DESC";
      $resA = mysql_query($sqlA) or die("$sqlA:".mysql_error());
      list($isThere) = mysql_fetch_row($resA);
      if ($isThere)
      {
         $table_list[] = $table;
      }
    }
     
    foreach ($table_list as $table) { 
        $sql = "SELECT votes_up FROM `$table` WHERE `site` LIKE '$entry' ORDER BY votes_up DESC"; 
        $sql1 = mysql_query($sql) or die("$sql:".mysql_error());
       while ($row = mysql_fetch_assoc($sql1)) {
           echo $table . ': "' . $row['votes_up'] . " for $entry from $table\"<br />";
       } 
    }
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    you need to troubleshoot when you're code is not working and is not producing an error that we could understand.

    why don't you echo your $sql variables, take those and plug them into a mysql client, run the query manually to see if the output is even what you're looking for.



    Dan

    Comment

    • yangyucn
      New Member
      • Jun 2009
      • 2

      #3
      so confused, i dont know what u r going to do...

      if u wanto sort the result, u should code like this:

      Code:
      $sql = "SELECT * 
      		FROM `table_name` 
      		WHERE `id` = '".$id."' 
      		ORDER BY `timestamp` DESC  ";
      $query = mysql_query($sql);
      while ($rt = mysql_fetch_assoc($query)){
      	echo '<pre>';
      	print_r ($rt);
      	echo '</pre>';
      }

      Comment

      Working...