A
Anonymous
Guest
I want to manually sort items from a table. The background is that I have different items listed grouped on item type and then sorted by the id so the article numbers are presented as
The sql string is shown below.
Instead of sorting the article numbers based on id ASC I want to sort them by a defined array like
The items shall be listed grouped on item and the article numbers shall be sorted as the arrays $sortItem1 and $sortItem2. The result should then be
I don't think the code below is possible but I want it to be sorted like
What is the best solution for this?
Code:
Item type 1 - 4109
Item type 1 - 1342
Item type 1 - 3193
Item type 2 - 6971
Item type 2 - 0484
The sql string is shown below.
Code:
$sql = "SELECT * FROM '".$table."' WHERE model = '".$model."' ORDER BY item, id ASC";
Instead of sorting the article numbers based on id ASC I want to sort them by a defined array like
Code:
$sortItem1 = [1342, 4109, 3193];
$sortItem2 = [0484, 6971];
The items shall be listed grouped on item and the article numbers shall be sorted as the arrays $sortItem1 and $sortItem2. The result should then be
Code:
Item type 1 - 1342
Item type 1 - 4109
Item type 1 - 3193
Item type 2 - 0484
Item type 2 - 6971
I don't think the code below is possible but I want it to be sorted like
Code:
ORDER BY item, $sortItem1, $sortItem2
What is the best solution for this?