I want to create a MySQL select function where I need to check if a value is in an array.
I Googled and found that I should use the IN function but I don't know how to construct it.
So here is the IN example
mysql> SELECT * FROM employee_tbl
-> WHERE daily_typing_pages IN ( 250, 220, 170 );
+------+------+------------+--------------------+
| id | name | work_date | daily_typing_pages |
+------+------+------------+--------------------+
| 1 | John | 2007-01-24 | 250 |
| 2 | Ram | 2007-05-27 | 220 |
| 3 | Jack | 2007-05-06 | 170 |
| 4 | Jill | 2007-04-06 | 220 |
+------+------+------------+--------------------+
I have an array in the daily_typing_pages column where I want to search in. So I wanted to do the following but that didn't work:
$sql = "SELECT * FROM $wpdb->postmeta WHERE meta_key = 'brand' IN (meta_value = '$brand')";
Brand is the column I want to search in.
I hope I make some sence because I pretty much lost it :-)
Aucun commentaire:
Enregistrer un commentaire