Why is this PHP / mySQL query giving me an error? -


i generating first part of query this:

while ($all_products = $db->fetch_array($all_prods))         {             $filter_string .= 'and product_id !=';             $filter_string .= $all_products['item_id'];             $filter_string .= ' '; } 

and second part this:

$sql_more_items = $db->query("select * db_products  owner_id='" . $user_id . "' , active=1 '" . $filter_string . "'  order rand() limit 10"); 

however it's giving me mysql syntax error , $filter_string part strangely adds ' twice before , after string, runs this:

where user_id='12345' , active=1 'and product_id !=0001 , product_id !=0002 ' order rand ...

what doing wrong?

$filter_string adds ' because put there. :p

try double quotes around $filter_string:

$sql_more_items = $db->query("select * db_products owner_id='" . $user_id . "' , active=1 " . $filter_string . "order rand() limit 10"); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -