[英]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 但在PHP中,此查询不起作用: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. 我认为问题出在'$ ch'变量。 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 它有效:s
@Bahumat100, if you think you have  
@ Bahumat100,如果您认为自己有 
to make space which is causing problem, then use html_entity_decode
and do it like this: 要腾出空间来引起问题,请使用html_entity_decode
并按以下步骤进行操作:
$req = "SELECT * FROM ".$table." WHERE PrestaCmd LIKE '%".html_entity_decode($ch)."%'";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.