cturner Posted October 7, 2007 Share Posted October 7, 2007 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(); Quote Link to comment Share on other sites More sharing options...
fenway Posted October 7, 2007 Share Posted October 7, 2007 What does you calendar table look like? Why are you running queries in a for loop? Quote Link to comment Share on other sites More sharing options...
cturner Posted October 7, 2007 Author Share Posted October 7, 2007 I am running queries in a for loop so that I can display the dates that should have links. The rest of the dates are suppose to display as non link dates. Click here to see what my calendar looks like. Quote Link to comment Share on other sites More sharing options...
cturner Posted October 7, 2007 Author Share Posted October 7, 2007 Here is what my table structure looks lik: Calendar id // auto_incremented primary key number day date month year time eventname eventdescription Quote Link to comment Share on other sites More sharing options...
cturner Posted October 8, 2007 Author Share Posted October 8, 2007 Did I say that this is quite urgent to be solved? Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted October 8, 2007 Share Posted October 8, 2007 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 Quote Link to comment Share on other sites More sharing options...
cturner Posted October 8, 2007 Author Share Posted October 8, 2007 I kind of know that ~n[EO]n~. Quote Link to comment Share on other sites More sharing options...
fenway Posted October 9, 2007 Share Posted October 9, 2007 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. Quote Link to comment Share on other sites More sharing options...
cturner Posted October 10, 2007 Author Share Posted October 10, 2007 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 Quote Link to comment Share on other sites More sharing options...
fenway Posted October 10, 2007 Share Posted October 10, 2007 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. Quote Link to comment Share on other sites More sharing options...
cturner Posted October 10, 2007 Author Share Posted October 10, 2007 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. Quote Link to comment 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.