0

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?

owner
  • 1
  • 2
  • 2
    add `order by` to your sql and order by the name not the ID – Dave Jun 28 '13 at 13:55
  • Are you using any aggregating functions? – Strawberry Jun 30 '13 at 10:39
  • I don't know what you mean by "aggregating functions" (i don't know to much about PHP and MySQL). The above code works OK, only i can't make it to chose the IDs consecutive (it chose the lastest from table). i found like my problem here: http://stackoverflow.com/questions/11431279/how-can-get-records-after-specific-id-in-mysql but i don't know to put it my code. – owner Jun 30 '13 at 10:51

2 Answers2

2

Just add to the end of your query:

ORDER BY name DESC //Or whatever serves as name
sybear
  • 7,837
  • 1
  • 22
  • 38
0

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

bombadil
  • 5
  • 4
  • I need to be the same every time. Doesn't matter the version of phone. I wish to be eliminated "random" forver :) – owner Jun 28 '13 at 14:08
  • I think if you do the other suggested answers you will avoid random forever! It will be in order though, but since you don't care, then it should work! – bombadil Jun 28 '13 at 14:20
  • please show me in the code because i put "order by" at the end of "$sql ..., $str_category ... and $sql = " SELECT * FROM ..." but the same behavior. Can you modify the entire line(s) of code where need the changes. thank you. – owner Jun 28 '13 at 14:25
  • make the edits in your original post so I can see what you've already done – bombadil Jun 28 '13 at 14:48
  • just to make sure `id` is a column in your table? Also why didn't you add the `ORDER BY` to the first query? – bombadil Jun 28 '13 at 15:14
  • yes id is a column. if i put ORDER BY at the first query returns "none" (no items found) – owner Jun 28 '13 at 18:40