Forum Moderators: coopster
I'm having some trouble in getting this work, due to the fact that I am trying to compare a value from the array to a value within the loop, I presume an integer value.
What I am trying to create here is a blog calendar format whereby you click on a particular link on the calendar which will link to a news article.
The idea behind this is store all the values from a SQL query into an array. Then compare each value from the array to each day in the loop. Somehow its not adding the link because due the if statement (See below)
Any suggestions:
Thanks
DW
CODE:
<?
$result=mysql_query("SELECT distinct DAY(story_date) as Day
FROM tbl_news
WHERE tbl_news.ncid=10
and YEAR(story_date)='2007'");
// STORE VALUES FROM DB INTO AN ARRAY
while (list($DBDay)=mysql_fetch_row($result))
{
$days[]=$DBDay;
}
?>
<table width="160" border="1" cellspacing=0 cellpadding=2>
<tr>
<td colspan="7"><? echo $month_name . " " . $year?></td>
</tr>
<tr>
<td>Su</td>
<td>M</td>
<td>T</td>
<td>W</td>
<td>Th</td>
<td>F</td>
<td>Sat</td>
</tr>
<?
// begin placement of days according to their beginning weekday
$day = 1;
$wday = $first_week_day;
$firstweek = true;
$cnt=0;
while ($day <= $lastday)
{
if ($firstweek)
{
echo '<tr>';
for ($i=1; $i<=$first_week_day; $i++)
{
echo '<TD> </td>';
}
$firstweek = false;
}
if ($wday==0)
{
echo '<tr>';
}
// make each day linkable to the following result.php page
if (intval($month_num) < 10)
{
$new_month_num = "0$month_num";
}
elseif (intval($month_num) >= 10)
{
$new_month_num = $month_num;
}
if ( intval($day) < 10)
{
$new_day = "0$day";
}
elseif (intval($day) >= 10)
{
$new_day = $day;
}
echo $days[$cnt].' '.$day.'<br>';
// COMPARISON THIS IS WHERE ITS SUPPOSE TO ADD A LINK
if ($days[$cnt]==$day)
{
echo "<td><a href=results.php?eventid=$link_date> $day </a></td>";
}
else
{
echo "<td>$day</td>";
}
#$link_date = "$year-$new_month_num-$new_day";
#echo "<td><a href=results.php?eventid=$link_date> $day </a></td>";
if ($wday==6)
{
echo '</tr>';
}
$wday++;
$wday = $wday % 7;
$day++;
$cnt++;
}
?>
</table>