首页 > 解决方案 > Delete id if not in database from a value

问题描述

I am trying to check the ids of the values that exist in the database. I know how to check if a single id exists, but I don't know how to check multiple ids. If there is an id that does not exist from database then delete non existing id in the value.

For example: $value = '1,2,3,4,6,7,8'; so check this ids from database if 2 and 3 is not exist from database and remove those ids in the value $value = '1,4,5,6,7,8';

Note: I just want to remove non existing id from value not from database.

标签: phpmysqldatabase

解决方案


SELECT GROUP_CONCAT(id SEPARATOR ',') AS `ids` FROM table_name WHERE id IN (1,2,3,4,6,7,8);

The above query returns a result which shows only the existing id. update table name, id field and input string as per your need.


推荐阅读