Error on query

For programming and general questions on Zend Framework

Error on query

Postby brosjr on Tue Dec 11, 2012 3:00 pm

Hello,

Maybe I'm doing something different from usual, but I'm new on this stuff and I would appreciate some tips. The point is, I have a page with many fields to make a search on a table database, most of then are "select" fields type.

If I build the statement like the following line it returns to me the result I want correctly:

$ent = $table->fetchAll(array('impmte_group = ?' => 'Food'));

All the fields have an "All" option, and to solve this I tryed to make a if clause for each select field like following that joins each part of the search statement into the $pesq like:

if($data[p_group] != 'All'){
$pesq .= "'impmte_group = ?' => '$data[p_group]'";
}

Then I end with this:

$ent = $table->fetchAll(array($pesq));

But I get the following error:

Message: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=> 'Food')' at line 1

I don't understand because, If I force the application to print to me the $pesq value, it returns correctly 'impmte_group = ?' => 'Food'.

Why this is not working? There is any other solution?
Thanks in advance
Danilo
brosjr
 
Posts: 13
Joined: Wed Nov 16, 2011 11:42 pm

Return to Zend Framework

Who is online

Users browsing this forum: No registered users and 7 guests