Jump to content

Need to know how to write IF statment to evauluate dates?


bobby317

Recommended Posts

on my code I am trying to evaluate the $day_num varable against the dates in my database which are stored using DATE in this format year-month-day.

 

Something like this:

 

$newdate = "$year-$month-$day_num";
if ($newdate == {$row['date']}) {
      something is done
}

 

Im not sure if I am on the right track below will be the whole code I am working on so you guys no. Thanks

 

<?php

//CSS style
print '<link href="eventMain.css" rel="stylesheet" type="text/css" />';

//This gets today's date  
$date = time ();  

//This puts the day, month, and year in seperate variables  
$day = date('d', $date);  
$month = date('m', $date);  
$year = date('Y', $date);  

//Here we generate the first day of the month  
$first_day = mktime(0,0,0,$month, 1, $year);   

//This gets us the month name  
$title = date('F', $first_day);

//Here we find out what day of the week the first day of the month falls on 
$day_of_week = date('D', $first_day);   

//Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero 
switch($day_of_week){  
case "Sun": $blank = 0; break;  
case "Mon": $blank = 1; break;  
case "Tue": $blank = 2; break;  
case "Wed": $blank = 3; break;  
case "Thu": $blank = 4; break;  
case "Fri": $blank = 5; break;  
case "Sat": $blank = 6; break;  
}  

//We then determine how many days are in the current month 
$days_in_month = cal_days_in_month(0, $month, $year);

//Database Connection
$dbc = mysql_connect('rwddesign.com:3306', 'rwddesi1_bobby31', 'jessica');
   mysql_select_db('rwddesi1_test');
   
//Query to pull all events from event table:
$query = "SELECT * FROM events WHERE date='$year-$month-$day_num'";

//Here we start building the table heads  
echo "<table>"; 
echo "<tr><th colspan=\"7\" class=\"title\"> $title $year </th></tr>"; 
echo '<tr><td class="dayOfWeek">Sunday</td><td class="dayOfWeek">Monday</td><td class="dayOfWeek">Tuesday</td><td class="dayOfWeek">Wendsday</td><td class="dayOfWeek">Thursday</td><td class="dayOfWeek">Friday</td><td class="dayOfWeek">Saturday</td></tr>';  

//This counts the days in the week, up to 7 
$day_count = 1;  echo "<tr>";

//first we take care of those blank days 
while ( $blank > 0 )  {  
echo "<td> </td>";  
$blank = $blank-1;  
$day_count++; 
}

//sets the first day of the month to 1  
$day_num = 1;  

while ( $day_num <= $days_in_month) {

if ($r = mysql_query($query)) {     //run the query.

		//Retrieve every record:
		while ($row = mysql_fetch_array($r)) {

		}

}

// Match calander dates with database dates
if () {

}

}

?>

Link to comment
Share on other sites

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.