Jump to content


Photo

Making a post calendar


  • Please log in to reply
6 replies to this topic

#1 Avalanche

Avalanche
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts

Posted 09 April 2003 - 08:34 PM

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.
DEFINE("YOU","Spending Too Much Time On The Computer");

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 09 April 2003 - 10:28 PM

[php:1:0812d558f0]
if ($r[\"title\"]==\'\') { $title=\'&nbsp;\'; } else { $title=$r[\"title\"]; }
[/php:1:0812d558f0]

&amp; = &
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 Avalanche

Avalanche
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts

Posted 10 April 2003 - 02:54 AM

How does that solve my problem exactly?
DEFINE("YOU","Spending Too Much Time On The Computer");

#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 10 April 2003 - 04:50 AM

is the data being returned for that specific day NULL?
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#5 Avalanche

Avalanche
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts

Posted 10 April 2003 - 05:46 PM

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.
DEFINE("YOU","Spending Too Much Time On The Computer");

#6 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 10 April 2003 - 05:56 PM

make an if else construct...

[php:1:83ec9adce4]<?php
// run query
// if mysql_num_rows(query) is equal to 0
// print out \'<td>&nbsp;</td>\'
// else
// use the code you have posted
?>[/php:1:83ec9adce4]
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#7 Avalanche

Avalanche
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts

Posted 10 April 2003 - 08:01 PM

Okay, I figured it out, thanks.
DEFINE("YOU","Spending Too Much Time On The Computer");




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users