简体   繁体   中英

PHP and MySQL - sort or group - after the ID

UPDATE: 30.06.2013

$phonesRelated = $DB->getRandom(" `".DB_PREFIX."phones` a, `".DB_PREFIX."phones_categories` b ", " a.id ", " AND a.id=b.phone_id AND b.phone_id!='".$phone['id']."' AND b.category_id IN (".implode(",", $arr).") GROUP BY a.id", 3);
$smarty->assign("phones", $phonesRelated);

Hi,

  1. ".DB_PREFIX."phones - represent the table with phones which have more columns (once is ID)

  2. ".DB_PREFIX."phones_categories - represent the table with 2 columns (phone_id[have the same number with ID from ".DB_PREFIX."phones ] and category_id[is the number of the category])

example: we're on webpage iphone3 which have the ID=7 in table ".DB_PREFIX."phones on column ID .

What i need is to make the query return the phones ID after the ID=7 -> ID=8,ID=9,ID=10. At this moment the query returns records by IDs from the end of the table ".DB_PREFIX."phones_categories which are ID=46,ID=47,ID=48.

Can someone help me with a hint of what to add at the code to make it return the consecutive IDs?

只需添加到查询的末尾:

ORDER BY name DESC //Or whatever serves as name

Do you want them to be in order as in: Iphone5, Iphone4s, Iphone4... or do you not care, as long as it is the same every time?

If the first is the case, then do the previous answer suggested, if not, then you will need to make sure that when you are entering the rows into your table, you do that in the same order every time

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM