tags:

views:

62

answers:

2

Hello

I want to sort data from mysql.

The shema looks like this:

  id    int(11)        
  objectId  int(11)    
  type          tinyint(4)    
  field     tinyint(4)    
  value     int(11)    
  date          int(10)

id  objectId  type  field  value  date
1   1631  0  10  2918  1183  746534
2   1631   0   11   1108   1183  746534

Now My problem is I can't order by objectId and date Any idea?

+1  A: 

If you want to order by object id first then date:

SELECT * FROM table_name ORDER BY objectId, date

If you want to order by date then object id:

SELECT * FROM table_name ORDER BY date, objectId

To get the results in PHP in the same order:

$res = mysql_query ("SELECT * FROM table_name ORDER BY date, objectId");

while ($row = mysql_fetch_object($res))
{
    echo "Object id: $row->objectId Date: $row->date\n";
}
rogeriopvl
this returns 532 0 0 20 0 0547 0 0 21 0 0
streetparade
"SELECT * FROM rankingHistory WHERE objectId >0 ORDER BY objectId, field, date LIMIT 30"this gives me all the object id ordered by field date and objectIdnow i want to sort that in php any idea?
streetparade
That is already sorted... by date and objectid. You just have to loop through the result set to get values in that order. Check my response edit.
rogeriopvl
A: 

if your dates and objectids are identical, it won't be much use sorting by them

Nick