Jump to content

Problem with query in php mysql?


shams

Recommended Posts

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>

<?php
include '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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.