owner
owner

Reputation: 1

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?

Upvotes: 0

Views: 114

Answers (2)

bombadil
bombadil

Reputation: 5

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

Upvotes: 0

sybear
sybear

Reputation: 7784

Just add to the end of your query:

ORDER BY name DESC //Or whatever serves as name

Upvotes: 2

Related Questions