How to sort PDO query based on predefined data

hello,

The following key fields are the product code
PDO wants the items in this series to be in the first place in the query, the rest is other products.
How do I do this?

Array
(
    [SY1049] => 4,
    [R0805300310] => 4,
    [OPA2354AIDGKR ] => 15,
    [CL0805056050] => 22,
    [FDC6333C] => 13
)

The following ORDER BY term in the query should work -

ORDER BY product_code IN('SY1049', add the rest of the values in the list here...) DESC

However, when you find yourself hard-coding values, it generally means you are doing something the hardest way possible. What is it about these values that causes them to be selected, that you could use in the query so that the query does the work of finding them, rather than you listing them out? Are they all from the same product type/category/manufacturer, the most frequent items used, items in stock, …? And if there’s no existing piece of data that would allow you to select them in a query, would adding such a piece of data make sense?

Thank you for your help

what am i trying to do:
This list contains material

I determine and save how much amount of which material is used for X product.
Later, when I log in because 10 X products have been produced, the materials are reduced from the stock.

I found a solution like this:
When I choose which material and how much to use with the Select option, I send it to the page in the pagination code as an array with ajax and save the amounts in a column in the table.
(When each quantity is selected, I delete all the numbers in the quantities column and rewrite it with the last string that came with ajax)
When the query runs again for pagination, I sort according to the quantity column and the materials whose quantities are determined are sorted from the top of the list. As seen in the picture.

When I submit a form with the save button, I write the quantity in the “quantities” column in the material table and the material code in the other “deduct_from stock” table.

looks good for now

gif screen test video
video3

Sponsor our Newsletter | Privacy Policy | Terms of Service