Jump to content

Making a post calendar


Avalanche

Recommended Posts

Hello.

 

I am making a journal/web blog type of thing, and I\'m going to have a calendar that lists any posts made on whichever days. I have:

 

[php:1:df95bb1102]<?php

 

include \"config.php\";

 

$db = mysql_connect($db_host,$db_user,$db_pass);

mysql_select_db ($db_name) or die (\"Cannot connect to database\");

/* We have now connected, unless you got an error message */

/* Lets display the current titles, so we can select one for editing */

echo \"Please click on a command next to a title to execute<br>the corresponding command on the corresponding entry:<p>\";

$query = \"SELECT id, title FROM news WHERE date=\'2003-04-01\' ORDER BY id DESC\";

$result = mysql_query($query);

/* Here we fetch the result as an array */

while($r=mysql_fetch_array($result))

{

/* This bit sets our data from each row as variables, to make it easier to display */

$id=$r[\"id\"];

$title=$r[\"title\"];

/* Now lets display the titles */

echo \"<table border=\'1\' cellspacing=\'2\' cellpadding=\'2\'><tr>\";

echo \"<td align=\'center\' valign=\'center\' colspan=\'7\'><FONT face=Verdana color=black size=10><b><u>April</u></b></td></tr>\";

echo \"<tr><td width=\'85\' height=\'15\' align=\'center\' valign=\'center\'><FONT face=\'Times New Roman\' color=\'white\' size=\'3\'><u>Sunday</u></font></td>\";

echo \"<td width=\'85\' height=\'15\' align=\'center\' valign=\'center\'><FONT face=\'Times New Roman\' color=\'white\' size=\'3\'><u>Monday</u></font></td>\";

echo \"<td width=\'85\' height=\'15\' align=\'center\' valign=\'center\'><FONT face=\'Times New Roman\' color=\'white\' size=\'3\'><u>Tuesday</u></font></td>\";

echo \"<td width=\'85\' height=\'15\' align=\'center\' valign=\'center\'><FONT face=\'Times New Roman\' color=\'white\' size=\'3\'><u>Wednesday</u></font></td>\";

echo \"<td width=\'85\' height=\'15\' align=\'center\' valign=\'center\'><FONT face=\'Times New Roman\' color=\'white\' size=\'3\'><u>Thursday</u></font></td>\";

echo \"<td width=\'85\' height=\'15\' align=\'center\' valign=\'center\'><FONT face=\'Times New Roman\' color=\'white\' size=\'3\'><u>Friday</u></font></td>\";

echo \"<td width=\'85\' height=\'15\' align=\'center\' valign=\'center\'><FONT face=\'Times New Roman\' color=\'white\' size=\'3\'><u>Saturday</u></font></td></tr>\";

echo \"<tr><td width=\'85\' height=\'85\' align=\'left\' valign=\'top\'></td>\";

echo \"<td width=\'85\' height=\'85\' align=\'left\' valign=\'top\'></td>\";

echo \"<td width=\'85\' height=\'85\' align=\'left\' valign=\'top\'><FONT face=\'Verdana\' color=\'white\' size=\'2\'><b>01 - </b><A HREF=\'main.php?page=view_entry.php&id=$id\'>$title</a></font></td>\";

}

 

mysql_close($db);

 

?>

 

 

<?php

 

include \"config.php\";

 

$db = mysql_connect($db_host,$db_user,$db_pass);

mysql_select_db ($db_name) or die (\"Cannot connect to database\");

/* We have now connected, unless you got an error message */

/* Lets display the current titles, so we can select one for editing */

$query = \"SELECT id, title FROM news WHERE date=\'2003-04-02\' ORDER BY id DESC\";

$result = mysql_query($query);

/* Here we fetch the result as an array */

while($r=mysql_fetch_array($result))

{

/* This bit sets our data from each row as variables, to make it easier to display */

$id=$r[\"id\"];

$title=$r[\"title\"];

/* Now lets display the titles */

echo \"<td width=\'85\' height=\'85\' align=\'left\' valign=\'top\'><FONT face=\'Verdana\' color=\'white\' size=\'2\'><b>02 - </b><A HREF=\'main.php?page=view_entry.php&id=$id\'>$title</a></font></td>\";

}

 

mysql_close($db);

 

?>[/php:1:df95bb1102]

 

A bit big, and can probably be shrunken and still work, but I don\'t care.

My problem is that it looks for data that was posted on the date of, let\'s say the 1st, but if there is no data that was posted on the first then the whole query doesn\'t show up, which means a chunk of my table would be missing.

 

So, is there any way to make it do something different if there is no data that has the date on the 1st?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/331-making-a-post-calendar/
Share on other sites

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.