Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.