I’ve got two tables, customer and reservations. customer and reservations both contain a row called customerID. reservations contains two columns named resStart and resEnd that only have dates in them (YYYY-MM-DD, which is the exact format I’ll be using to establish the $todaysdate variable.
I’d like to join those two to produce a table with single column of customerID along with other info, but only if $todaysdate falls on or between two dates. Note: $todaysdate is established elsewhere in my documents as either a _GET from url (ie. day.php?date=2012-07-04) or if none is established, today’s date with date(‘Y-m-d’). This part of the code is not where my problems are lying, I’m sure of that. I’m thinking it’s a syntax error somewhere while defining the information in the mySql query.
Here’s what I’m working with. A little explanation: I’m wrapping PHP code around Javascript, and the goal here is to produce a separate DIV for each resStart. The Javascript is fetching offset variables to add to the CSS of each DIV, so each DIV is automatically placed relative to the equipment it’s representing.
<?php
$getreservations = mysql_query("
SELECT * FROM customer LEFT JOIN reservations WHERE ( customer.customerID = reservations.customerID )
AND ($todaysdate = resStart OR $todaysdate >= resStart AND $todaysdate <= resEnd )
")
or die(mysql_error());
while( false !== ($row = mysql_fetch_assoc($getreservations)))
{
$nameLast = $row["nameLast"];
$nameFirst = $row["nameFirst"];
$customerID = $row["customerID"];
$equipID = $row["equipID"];
$resStart = $row["resStart"];
$resEnd = $row["resEnd"];
$timeStart = $row["timeStart"];
$timeEnd = $row["timeEnd"];
$result = strtotime($timeStart);
$minute = date("i", $result );
$second = date("s",$result );
$hour = date("H", $result );
if(true) {
?>
<script language='javascript'>
var left = $('#<?php echo("$hour$minute");?>').offset().left;
var top = $('#<?php echo $equipID;?>').offset().top;
$(document).ready(function() {
$('#<?php echo ("$customerID$equipID");?>).css( { 'left': (pos.left + width) + 'px', 'top': (pos.top + top) + 'px' } );
}
</script>
<?php }
echo ("<div class='resContainer $customerID$equipID' id=$customerID$equipID>$nameLast, $nameFirst</div> ");
} ?>
However, You can also get the “todaysdate” in SQL:
DATE(NOW()), and the statement will be:EDIT: added quotes around
$todaysdatevariable to avoid confusion