Jump to content

[SOLVED] Non link dates aren't displaying???


cturner

Recommended Posts

My code that is below is suppose to display dates as links only if there is an event for that date. Also if there is no event for a date it is suppose to display just the date. However it is just displaying all dates as links. Can someone please help me work this out? Thanks in advance. I have posted this in the MySQL Help forum because I think that the problem has something to do with the mysql code.

 

require "config.php";
// more code is here
for ($list_day=1;$list_day<=$daysinmonth;$list_day++) {
$month = date('F');
$year = date('Y');
// WHERE month = '$month' AND year = '$year' GROUP BY month
$query2 = mysql_query("SELECT id, month, year FROM calendar GROUP BY month") or die ("Could not query because: ".mysql_error());
while ($row2 = mysql_fetch_array($query2)) {
if (($row2['month'] == $month) && ($row2['year'] == $year)) {
   		echo "<td><a href=event.php?id=".$row2['id'].">" . $list_day . "</a></td>";
} elseif (($row2['month'] != $month) && ($row2['year'] != $year)) {
	echo "<td>".$list_day."</td>";
}
}
// more code is here also
mysql_close();

Link to comment
Share on other sites

I think the problem is here, where have u checked for the events in if...else , i only see you are checking the db month and year with current month and year and giving a link to it.... too confusing

 

<?php if (($row2['month'] == $month) && ($row2['year'] == $year)) {
echo "<td><a href=event.php?id=".$row2['id'].">" . $list_day . "</a></td>";
} elseif (($row2['month'] != $month) && ($row2['year'] != $year)) {
echo "<td>".$list_day."</td>";
}
?>

in ur date id=1 is passed in every date.

http://blueguminteractive.biz/bdgp/event.php?id=1

Link to comment
Share on other sites

I'm confused as to why you're not storing the events with a pure datetime field... but even so, you should simply retrieve all the events for a given month with a single sql statement, and then iterate though the days, and check for matching ones.

Link to comment
Share on other sites

When someone clicks on a link it is suppose to display the whole date in a different page. I still can't get the date links to display. :(  ???

 

Here is my updated code:

require "config.php";
// more code here
$year = $_GET['year'];
$month = $_GET['month'];
// WHERE startmonth = $month AND startyear = $year
$sql = "SELECT startdate, startmonth, startyear FROM calendar WHERE startmonth = '$month' AND startyear = '$year'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
  $days_with_events[] = $row['startdate'];
}

//day 0 of the next month returns the last day of the current month
$last_day_of_month = date("j", mktime(0, 0, 0, $month+1, 0, $year));
for ($i = 1; $i <= $last_day_of_month; $i++) {
  if (in_array($i, $days_with_events)) {
    echo "<td><a href=\"event.php?date=" . $i . "&month=" . $month . "&year=" . $year . "\">" . $i . "</a></td>";
  } else {
    echo "<td>".$i."</td>";
  }
  
  if ($theday == 6) {
   	   echo "</tr>";
       echo "<tr>";
       $theday = -1;
   }
   $theday++;
  
  echo " ";

 

I have changed my table structure to:

Calendar

id

startday

startdate

startmonth

startyear

starttime

endday

enddate

endmonth

endyear

endtime

// rest is irrelevant to the code above

Link to comment
Share on other sites

Table structure is less than ideal... but let's get the script to work first.

 

Sounds like in_array() isn't doing what you think it's doing... nor is it possibly efficient.  I'd build a hash.  Are you sure it's not doing a string comparison?  Check the output of $row['startdate'] and what you think $i is.

Link to comment
Share on other sites

Problem solved. The solution was I put:

$realmonth1 = date('F', mktime(0, 0, 0, $current_month-1, date("d"),  date("Y")));
$realmonth2 = date('F', mktime(0, 0, 0, $current_month+1, date("d"),  date("Y")));
$realyear1 = date('Y', mktime(0, 0, 0, $current_month-1, date("d"),  date("Y")));
$realyear2 = date('Y', mktime(0, 0, 0, $current_month+1, date("d"),  date("Y")));

above all of the code. Then placed those variables in a query string. :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.