Jump to content

[SOLVED] mysql query + sort strangeness


skippylou

Recommended Posts

Have a strange one here.

 

First if I attempt this query from the mysql command line, it displays the results properly sorted by the fbytes field descending:

 

mysql> SELECT fproto, fport, SUM(fbytes), AVG(fbytes) FROM flow_ports GROUP BY fproto, fport ORDER BY 'SUM(fbytes)' DESC;

 

When I have the same query in my php code, it randomly displays data in an order that is not desc from most to least by the SUM(fbytes):

 

$sql = "SELECT fproto, fport, SUM(fbytes), AVG(fbytes) FROM flow_ports GROUP BY fproto, fport ORDER BY 'SUM(fbytes)' DESC";

$result = mysql_query( $sql );

while($row = mysql_fetch_array($result)) {

# table glue here

  echo $row;

# table glue here

}

 

Any thoughts on why a query that works perfectly from the mysql command line would behave differently as far as sort order in php?

 

Thanks,

 

Scott

Link to comment
https://forums.phpfreaks.com/topic/86241-solved-mysql-query-sort-strangeness/
Share on other sites

I left it out, because I didn't think it mattered (but maybe it does), but in the table it actually isn't: echo $row.  The columns are filled with:

 

echo $row['fproto'];

echo $row['fport'];

echo $row['SUM(fbytes)'];

echo $row['AVG(fbytes)'];

 

There doesn't appear to be any sorting going on amongst any of the columns in the php query.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.