views:

61

answers:

1

Hi,

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 query, 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

+1  A: 

@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)."%'";
shamittomar
I would just not encode it....
Col. Shrapnel
@Col. yes I completely agree but what if the `$ch` variable is coming from somewhere (some other function / file) which is not easily changeable. In that case this would be an easy fix.
shamittomar
No, html_entity_decode not worked.
bahamut100
But I just use str_replace : $ch2 = str_replace(" "," ",$ch); and it works.
bahamut100