PDA

View Full Version : PHP and Dates HELP!


cocoonfx
10-17-2009, 11:33 AM
I have a PHP Query which is looking at 3 tables, in which the events table has a date field. I want the query to only get the data for the event from today +1. I.e if i went to the page I would want to see Sunday and Monday.

I have tried to do a variable $num = 1;

Then <?php echo $today+$num;?> This then gives me year 2010.

I have pasted the PHP code below to show you what I have done so far but I am a little stumped on how to get this to work.

CODE -----
<?PHP

$today =date("Y/m/d");

$date = date("Y/m/d")+$num;
$query =sprintf("SELECT * FROM wp_dbem_bookings a,wp_dbem_people b,wp_dbem_events c WHERE a.person_id=b.person_id and
a.event_id=c.event_id and c.event_start_date>='$today' and c.event_start_date<='$date' ORDER BY a.event_id");
$result =mysql_query($query);
$rowEvent = mysql_fetch_array($result);


?>

<?PHP echo $today;?>


<table width="100%" height="100%" border="1">
<tr>

<td width="6%"><span class="style3">Event ID</span></td>
<td width="6%"><span class="style3">Event Name</span></td>
<td width="6%"><span class="style3">Persons Name</span></td>
<td width="6%"><span class="style3">Payment Type</span></td>
<td width="6%"><span class="style3">Seats</span></td>
<td width="6%"><span class="style3">Event Date</span></td>

</tr>
<?php do{ ?>
<tr class="style1">
<td><div align="center" class="style2 style1"><?php echo $rowEvent['event_id'];?></div></td>
<td><div align="center" class="style2 style1"><?php echo $rowEvent['event_name'];?></div></td>
<td><div align="center" class="style2 style1"><?php echo $rowEvent['person_name'];?></div></td>
<td><div align="center" class="style2 style1"><?php echo $rowEvent['person_phone'];?></div></td>
<td><div align="center" class="style2 style1"><?php echo $rowEvent['booking_seats'];?></div></td>
<td><div align="center" class="style2 style1"><?php echo $rowEvent['event_start_date'];?></div></td>

</tr>
<?php }while ($rowEvent = mysql_fetch_array($result)); ?>
</table>
</table>

edbr
10-19-2009, 02:44 AM
date format this might help
http://www.tizag.com/phpT/phpdate.php

cocoonfx
10-21-2009, 11:10 AM
Thanks for that... what the site suggested worked. On to the next task.. :-D