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?
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";
}
如果您的日期和对象ID相同,则按它们进行排序不会有太大用处
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.