I have a problem calling the database where I used for loops.
database query 1
SELECT id,qtyslot FROM rack WHERE theid = '1'
Eg id = 2
and qtyslot = 12
We create for loops
for ($x = 1; $x <= 12; $x++) {
Here I call the database with the identity of the slot varies 1 or 2,4 (with comma from 2 to 4 slots) and etc.
HOW CAN SELECT
SELECT * FROM books WHERE idrack = '2' AND slot"......." // $x
The database structure as follow.
----------------------- | id | slot | name | ----------------------- | 1 | 1 | name | ----------------------- | 2 | 2,4 | name | --> How to define this with the above loop ($x) ----------------------- | 3 | 5,6 | name | --> How to define this with the above loop ($x) ----------------------- | 4 | 7 | name | -----------------------
And the result like this in table
----------------------------------------- | loop qtyslot | In slot | remark | ----------------------------------------- | 1 | name slot 1 | remark | ----------------------------------------- | 2 | | | ---------------| | | | 3 | Name slot 2,4 | remark | ---------------| | | | 4 | | | ----------------------------------------- | 5 | Name in | | ---------------| slot 5,6 | remark| | 6 | | | ------------------------------------------ etc up to 12
Can anyone help me.
You can use SUBSTRING_INDEX function in mysql. Try This :
SELECT * FROM books WHERE idrack = '2' AND $x BETWEEN SUBSTRING_INDEX(slot, ',', 1) and SUBSTRING_INDEX(slot, ',', -1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With