Jump to content

How to put dynamic php date into mysql query


TheChaosFactor

Recommended Posts

So I'm trying to put a user selected date into a mysql query, but it seems like no matter what I do I get 0 results even though I already know there's quite a few. The way I have it now 'echo $query;' puts out the expected results, but I'm guessing it's because I'm trying to match a date to a string.  I tried strtotime but I'm not sure if I was doing it right.. I also tried sprintf() just in case, but that doesn't seem to have a date feature.  The variable $realdate is just to show how I was attempting to use strtotime, it's not an actualy part of the script at this time...

 


$searchdate = $_GET['searchdate'];
//$realdate = strtotime($searchdate)


//connects to db
dbconnect();


$query="SELECT `name`, `date`, SUM(`amount`) as `total_money`, SUM(`bricks`) as `total_bricks` FROM Aces_Donations WHERE `date`= $searchdate ORDER BY `total_money`";

echo $query;

$result=mysql_query($query); 

//Opens the table
echo "<table border = '3' width = 40% bgcolor=#A85045><caption><center>Rankings - ".$searchdate.'</center></caption>';

//Loop to run until eof

while($row = mysql_fetch_array($result)){

echo "<tr><td>".$rank."</td>	<td>".$row['name']. "</td><td>". $row['total_money']."</td><td>".$row['total_bricks'].'</td></tr>';
$rank++;

}
echo '</table>';

But if I enclose a variable in single quotes won't it print the literal string that is that variable instead of the contents of the variable?

 

Edit: Just checked. It does try to query the variable container instead of the contents when it's placed in single quotes

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.