Select from MySQL Table Where Field='$Array'

Select from mysql table WHERE field='$array'?

Use IN:

$sql = "SELECT * FROM `myTable` WHERE `myField` IN (1,40,20,55,29,48)";

you can use implode(",", $array) to get the list together from the array.

MySQL: Select values from table where value is in array

Use mysql's IN, but ensure that the parenthesized list of image extensions contains strings which are in quotes.

Your code at Update 2 is almost there, but you have a problem at this line:

$image_array=implode(",", $image_exts);

$image_array ends up being jpg,jpeg,gif,png,bmp,webp when really you need it to be 'jpg','jpeg','gif','png','bmp','webp' for it to be usable in your query.

Replace that line of code with:

$image_array = "'" . implode("','", $image_exts) . "'";

Keep the rest of your code, and see if that works.

How to select a row from array in column in mysql

select * from table_name where FIND_IN_SET(@user_id,user_id) > 0

SELECT all rows by one field and different values

You can use IN clause to fetch all the objects

SELECT * FROM objects WHERE agent IN ('4', '5', '7','8','9') 
AND status='$st' ORDER BY id DESC

How to apply mysql join on a column having array field in table?

Here's how to fix it:

CREATE TABLE user_products (
user_id INT,
product_id INT,
PRIMARY KEY (user_id, product_id)
);

Fill one user and one product id into each row.

INSERT INTO user_products (user_id, product_id) 
VALUES (1,1), (1,2), (1,3), (2,5), (2,6), (3,4);

Now you can do the join this way:

SELECT * FROM users AS u
JOIN user_products AS up ON u.id = up.user_id
JOIN products AS p ON up.product_id = p.id;

Don't use JSON arrays for joins.



Related Topics



Leave a reply



Submit