[英]MySQL LIKE not working as expected
I am not getting the expected search result from my code , This is a segment from my SQL Table 我没有从代码中获得预期的搜索结果,这是我的SQL表中的一部分
Nom Description
41099 Screen truck Hire for Northern Racing
41100 Dry Hire - Screen
41101 Dry Hire - Kit
41102 Screen Truck Hire for chester / Bangor Dee
41103 Blackburn Digiboard Backup DVD-DO NOT USE
This is my PHP code and I am getting the expected results until I search for 'chester' , when I get no result . 这是我的PHP代码,在没有结果的情况下,直到搜索“ chester”之前,我都得到了预期的结果。 Can anyone tell me what is going wrong please ?
谁能告诉我出什么问题了吗?
PHP Code to retrun XML Data PHP代码重新运行XML数据
echo '<sites>' ;
$condition = "Description LIKE '%chester%' ";
$result = mysql_query("SELECT * FROM jbe_nominal_codes WHERE $condition") ;
while($row = mysql_fetch_array($result)) {
$nom = $row['nominal'] ;
if (!$nom) { $nom= "0000" ; } ;
$des = $row['Description'] ;
if (!$des) { $des= "No Description" ; } ;
echo "<NameSearch> " ;
echo '<nominal>';
echo $nom;
echo '</nominal>';
echo '<Description>' ;
echo $des ;
echo '</Description>' ;
echo "</NameSearch> " ;
} ;
a good practice is to extend your mysql_ statement. 一个好的做法是扩展您的mysql_语句。
mysql_query("SELECT * FROM jbe_nominal_codes WHERE $condition")or die(mysql_error());
mysql_query(“ SELECT * FROM jbe_nominal_codes WHERE $ condition”)或die(mysql_error());
if a error is thrown, you know there is something wrong in your query and you will get some hints from the error, if not, could it be that chester is not in the your db table at all? 如果抛出错误,您就知道查询中有问题,并且会从该错误中得到一些提示,如果不是,那是否可能是chester根本不在您的db表中?
like previously said, you should take note of mysqli and PDO and why you should not use mysql_ anymore. 如前所述,您应该注意mysqli和PDO,以及为什么不应该再使用mysql_了。 Why shouldn't I use mysql_* functions in PHP?
为什么我不应该在PHP中使用mysql_ *函数?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.