I have following array in PHP:
$arr = [1, 3, '4A', '5A', '5C', '2B', '2C', '2E'];
Somehow I need to convert this array to a string which look like this:
$filter = "(id like '1%') OR
(id like '3%') OR
(id like '4A%') OR
(id like '5A%' OR id like '5C%') OR
(id like '2B%' OR id like '2C%' OR id like '2E%')";
The first character of the array value indicates a unique categorie and is wrapped in parentheses. In the end I will use this to query the database;
$sql = "SELECT * FROM list WHERE {$filter}";
Can someone help me converting this array to the correct string ? What is the best method to achieve this ?
To give you an idea of what I'm trying: The 'id' column in my database row looks like; 1B2875. Where the first char (1) indicates a categorie and the second char (B) the subcategorie. The given array is a result of a client-side filter request.
categoryand just make theIDan auto_increment integer. This setup youre working with now is probably going to cause a lot of hurt later.