Creating a Calendar with PHP/MySQL

Title says it all, but the difficulties I’m having are displaying the calendar.
[php]$conn = mysql_connect(“host”,“root”,“pass”);
if (!$conn) {
die('Could not connect to Server: ’ . mysql_error());
}
$db_selected = mysql_select_db(“schedule”,$conn);
if (!$db_selected) {
die ('Can’t Connect to Database : ’ . mysql_error());
}
$sql = mysql_query(“SELECT * FROM july”);
if (!$sql) {
die('Invalid query: ’ . mysql_error());
}
while($result = mysql_fetch_array($sql))
{
echo $result[“day”] . "
";
}[/php]

I’ve gotten this far, but the issue I’m having is that I need to display a certain amount of rows per week. So the first day in July starts on Monday, so it would have 6 days in it, then the next week is 7. I would think to use foreach, or something like that, but I am definitely not that skilled in this.

Thanks for your help!

The logic here is flawed my friend and probably causing you no end of headaches…

Every row will have 7 days, just that some may be blank (IE: no number)
Use that logic and should eliminated a few problems straight away.

Now, let’s say your displaying a table for the results, starting a new table row on the monday.
Do a check what day is currently printed in the loop, if it’s sunday, end the current row and start a new row.

Here’s a quick example of the top of my head;
[php]

<?php foreach($days as $day) { if($day == 'sunday') { print ''; } print ''; } ?>
' . $day . '
[/php]

Hope that helps
Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service