Ordering by number of rows?

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-05-12T04:00:33Z Indexed on 2010/05/12 4:04 UTC
Read the original article Hit count: 159

Filed under:
|
|
|

Alright, so I have a table outputting data from a MySQL table in a while loop. Well one of the columns it outputs isn't stored statically in the table, instead it's the sum of how many times it appears in a different MySQL table.

Sorry I'm not sure this is easy to understand. Here's my code:

    $query="SELECT * FROM list WHERE added='$addedby' ORDER BY time DESC";
    $result=mysql_query($query);
    while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
$loghwid = $row['hwid'];

$sql="SELECT * FROM logs WHERE hwid='$loghwid' AND time < now() + interval 1 hour";
$query = mysql_query($sql) OR DIE(mysql_error());
$boots = mysql_num_rows($query);

//Display the table
    }

The above is the code displaying the table.

As you can see it's grabbing data from two different MySQL tables. However I want to be able to ORDER BY $boots DESC. But as its a counting of a completely different table, I have no idea of how to go about doing that.

I would appreciate any help, thank you.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql