How to add a PHP variable inside REGEXP in mySQL
My code is like this
SELECT count(product_id) as totalCount FROM ref_products WHERE misc REGEXP '(.*\"level_id\":\'".$course_level_id."'\.*)'
How to add a PHP variable inside REGEXP in mySQL
My code is like this
SELECT count(product_id) as totalCount FROM ref_products WHERE misc REGEXP '(.*\"level_id\":\'".$course_level_id."'\.*)'
Assuming you use a double quoted string ("):
$sql = "SELECT count(product_id) as totalCount FROM ref_products WHERE misc REGEXP '(.*\"level_id\":\'".$course_level_id."'.*)'";
Assuming you use a single quoted string ('):
$sql = 'SELECT count(product_id) as totalCount FROM ref_products WHERE misc REGEXP \'(.*\"level_id\":'.$course_level_id.'.*)\'';
SELECT count(product_id) as totalCount FROM ref_products WHERE misc REGEXP '(.*"level_id":"'.$course_level_id.'".*)'
not working is not very descriptive. We don't know what you're thinking or the output you're getting -- we only know what you're telling us. So, please be descriptive and explain the issue.