Avalanche Posted April 9, 2003 Share Posted April 9, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/331-making-a-post-calendar/ Share on other sites More sharing options...
effigy Posted April 9, 2003 Share Posted April 9, 2003 [php:1:0812d558f0] if ($r[\"title\"]==\'\') { $title=\' \'; } else { $title=$r[\"title\"]; } [/php:1:0812d558f0] & = & Quote Link to comment https://forums.phpfreaks.com/topic/331-making-a-post-calendar/#findComment-1069 Share on other sites More sharing options...
Avalanche Posted April 10, 2003 Author Share Posted April 10, 2003 How does that solve my problem exactly? Quote Link to comment https://forums.phpfreaks.com/topic/331-making-a-post-calendar/#findComment-1070 Share on other sites More sharing options...
effigy Posted April 10, 2003 Share Posted April 10, 2003 is the data being returned for that specific day NULL? Quote Link to comment https://forums.phpfreaks.com/topic/331-making-a-post-calendar/#findComment-1071 Share on other sites More sharing options...
Avalanche Posted April 10, 2003 Author Share Posted April 10, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/331-making-a-post-calendar/#findComment-1074 Share on other sites More sharing options...
effigy Posted April 10, 2003 Share Posted April 10, 2003 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] Quote Link to comment https://forums.phpfreaks.com/topic/331-making-a-post-calendar/#findComment-1075 Share on other sites More sharing options...
Avalanche Posted April 10, 2003 Author Share Posted April 10, 2003 Okay, I figured it out, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/331-making-a-post-calendar/#findComment-1079 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.