Jump to content

Archived

This topic is now archived and is closed to further replies.

Avalanche

Making a post calendar

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.

Share this post


Link to post
Share on other sites

[php:1:0812d558f0]

if ($r[\"title\"]==\'\') { $title=\' \'; } else { $title=$r[\"title\"]; }

[/php:1:0812d558f0]

 

& = &

Share this post


Link to post
Share on other sites

is the data being returned for that specific day NULL?

Share this post


Link to post
Share on other sites

Since there is nothing that has that date, the echo sequence won\'t show up AT ALL, which means it doesn\'t add in the <td etcetera></td> tags nor does it add the title and rest, and then my calendar is off.

Share this post


Link to post
Share on other sites

make an if else construct...

 

[php:1:83ec9adce4]<?php

// run query

// if mysql_num_rows(query) is equal to 0

// print out \'<td> </td>\'

// else

// use the code you have posted

?>[/php:1:83ec9adce4]

Share this post


Link to post
Share on other sites

×

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.