shams Posted December 5, 2006 Share Posted December 5, 2006 hi,this is a mysql query shows the rows of table pharmacy with columns id,Code,Name ,Exp (the drug expiry date)and ExpLeft (Expiray Left for the drugs in months) for the drugs, the query is working fine without (WHERE ExpLeft='$ExpLef'), i want to query for the column ExpLeft for exmple for the drugs EcpLeft is 12 months, the code is not working with the query WHERE , there is no any error in ouput just shows the table headers.[code]<html><head><title>Open Pharmacy</title><style type="text/css">table tr td { font: 12px Verdana, Arial, sans-serif;text-align: center;font-weight: bold;}table tr th { font-size: 12px;text-align: center;}</style></head><body><?phpinclude 'library/config.php';include 'library/opendb.php';include 'library/paging_function.php';$ExpLef = $_POST['ExpLef'];// query the table$result = mysql_query("SELECT count(*) FROM pharmacy");$total = mysql_result($result, 0);$news = mysql_query("SELECT * FROM pharmacy WHERE ExpLeft='$ExpLef' ORDER BY id ASC LIMIT $start, $display");echo "<table border='1'>";echo "<tr><th>Id</th><th>Code</th><th>Name</th><th>ExpLeft</th></tr>";while($row = mysql_fetch_assoc($news)) {// Expiray Left in Months$Exp = $row[Exp];$expires=strtotime($Exp);$rightnow=time();$secondsleft=$expires-$rightnow;$ExpLeft=round($secondsleft/2592000);echo "<tr><td>";echo $row[id];echo "</td><td>";echo $row[Code];echo "</td><td>";echo $row[Name];echo "</td><td>";echo $ExpLeft;echo "</td></tr>";}echo "</table>";paginate($display, $pg, $total);include 'library/closedb.php';?></body></html> [/code][/code] Quote Link to comment Share on other sites More sharing options...
Darkness Soul Posted December 5, 2006 Share Posted December 5, 2006 Did you try to use ` instead of ' ? Or you aways can use \". Like:"SELECT * FROM pharmacy WHERE ExpLeft=`$ExpLef` ORDER BY id ASC LIMIT $start, $display""SELECT * FROM pharmacy WHERE ExpLeft=\"$ExpLef\" ORDER BY id ASC LIMIT $start, $display"Sometimes, when the mysql get a error, if some of columns doesn't existe, it will not generate a waring.. Take a note, use a $var to your sql, and use the mysql_query full.. like:[code]$sql = "SELECT * FROM pharmacy WHERE ExpLeft=\"$ExpLef\" ORDER BY id ASC LIMIT $start, $display" ;$query = mysql_query ( $sql , $conn ) or die ( $sql .'<br>'. mysql_error() )[/code]Try it, will show you the string its trying to execute and the mysql real error. :)D.Soul Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.