Forum Moderators: coopster

Message Too Old, No Replies

please check this php codes for mistake?

please check this php codes for mistake?

         

shams

1:53 am on May 14, 2006 (gmt 0)

10+ Year Member



hi,
this is a mysql query which work fine in mysql command line, i put it in php script when i run it there is just a blank page:
<?php
$var =$_POST['var'];
$date1 =$_POST['date1'];
$date2 =$_POST['date2'];
mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());
$query = "SELECT $var, COUNT(name) FROM register WHERE dateReg >= '$date1' and dateReg <= '$date2' GROUP BY $var";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)) {
echo "There are ".$row['COUNT(name)']." ".$row[$var]." "."TB"." "."patient(s)." "."from"." ".$row[$date1]." "."to"." ".$row[$date2];
echo "<br />";
}
?>

eelixduppy

2:57 am on May 14, 2006 (gmt 0)



Change the following lines of code:

>>>$query = "SELECT $var, COUNT(name) FROM register WHERE dateReg >= '$date1' and dateReg <= '$date2' GROUP BY $var";

>>>echo "There are ".$row['COUNT(name)']." ".$row[$var]." "."TB"." "."patient(s)." "."from"." ".$row[$date1]." "."to"." ".$row[$date2];

To the following, respectively:

$query = "SELECT $var,COUNT(name) as num_name FROM register WHERE dateReg >= '$date1' and dateReg <= '$date2' GROUP BY $var";

echo "There are ".$row['num_name']." ".$row[var]." TB patient(s) from ".$row[date1]." to ".$row[date2];

This should work now. Good luck!

eelix

shams

3:42 am on May 14, 2006 (gmt 0)

10+ Year Member



hi eelixduppy,
thanks so much for the help, the query was wonderfull, with little modefication the echo also worked perfect, this is the modefied echo:
echo "There are ".$row['num_name']." ".$row[$var]." TB patient(s) from ".$date1." to ".$date2;

eelixduppy

4:45 am on May 14, 2006 (gmt 0)



Sorry for the errors. I wasn't paying attention to what you extracted from the table, I sort-of followed what you had without actually reading what was there. :) Well I'm glad you got it!

eelix