I am not getting the expected search result from my code , This is a segment from my SQL Table
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 . Can anyone tell me what is going wrong please ?
PHP Code to retrun XML Data
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_query("SELECT * FROM jbe_nominal_codes WHERE $condition")or 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?
like previously said, you should take note of mysqli and PDO and why you should not use mysql_ anymore. Why shouldn't I use mysql_* functions in PHP?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.