Jump to content

Recommended Posts

hi,
i have the patients mysql table name is treatment, patients will collect thier drugs each month in the same date, it means for each patiens will be multiple entries with deferent id's because the id is auto_increment, ecach drug has it is own column, so the quantity will be entered in the ecah drugs column, i will enter the drug name and the months for that drug will be taken by the patients, this script will tell me the quanttity of that drug i need for the future:
[code]
<?php
$drug = 'PZA'; #$_POST['drug'];
$months = '4'; #$_POST['type'];

mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());
$result = mysql_query("SELECT SUM($drug) as total FROM treatment");
$total = mysql_result($result, 0, 'total');
$no = mysql_query("SELECT count($drug) FROM treatment");
$newtot = (($total/$no)*$months) - $total;
if($newtot) {
echo "You need ".$newtot." " ."tab of " .$drug;
}
else { echo "Sorry no match found";
}

?>
[/code]
but the output of this script is sorry no match found which is not the correct answer, any one can help please?
Your SQL queries are little wrong i belive. I think you should be doing something like this instead:
[code]$result = mysql_query("SELECT SUM(drug_col) as total FROM treatment WHERE drug_col='$drug'");[/code]
Note: before using that query make sure you change any instance of drug_col to the column name you are getting drug name from.

Also your secound query will need to be modified like above too.
[!--quoteo(post=373776:date=May 14 2006, 05:56 PM:name=crouchjay)--][div class=\'quotetop\']QUOTE(crouchjay @ May 14 2006, 05:56 PM) [snapback]373776[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]mysql_connect("localhost","root") or die(mysql_error()); [/code]

I am not totally sure, but I do believe you need a password in there.

Jay
[/quote]
He most probably took the password out for security reasons or hes developing the script locally on his local PC and his seup of mysql has no password set. So that isn't the problem but mainly to do with his SQL queries.
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.