query works on MySQL, but no in PHP, why?
I need to display the results of this query :
SELECT * FROM projects WHERE PrestaCmd LIKE '% A - CREP - DPE - %'
but in PHP, this query doesn't work :s
This is my code :
$req = "SELECT * FROM ".$table." WHERE PrestaCmd LIKE '%".$ch."%'";
echo $req; //returns : SELECT * FROM jos_projectlog_projects WHERE PrestaCmd LIKE '% A - CREP - DPE - %'
$results = mysql_query($req);
while ($row = mysql_fetch_array($results, MYSQL_ASSOC)) {
print_r($row);
}
I think the problem is coming from the '$ch' variable. But when I put an echo of the quer开发者_开发百科y, it's correct, and when I put a query like this :
$req = "SELECT * FROM jos_projectlog_projects WHERE PrestaCmd LIKE '% A - CREP - DPE - %'";
echo $req;
$results = mysql_query($req);
while ($row = mysql_fetch_array($results, MYSQL_ASSOC)) {
print_r($row);
}
it works :s
@Bahumat100, if you think you have  
to make space which is causing problem, then use html_entity_decode
and do it like this:
$req = "SELECT * FROM ".$table." WHERE PrestaCmd LIKE '%".html_entity_decode($ch)."%'";
精彩评论