ksduded Posted April 14, 2008 Share Posted April 14, 2008 I am building up a calender which shows events by retrieving data from the mysql database by looking up the selected date. The calender has clickable dates for retrieving the data. I wanted to remove the links from the dates which does not have any corresponding data in the database. So basically when i am generating each date on the calendar through a while loop, I want to check whether that specified date is available in the database, if there is no record of that date then i will run a specific code which makes that date on the calendar unclickable. So basically its a very simple way to compare whether there is a corresponding date (from a database field) with a looping date variable. while ( $day_num <= $days_in_month ) { $daydata = "2008-04-0".$day_num; while($comeon = mysql_fetch_array($result)) { if($comeon['prog_date'] != $daydata) { echo "<td bgcolor=#1a2e00>".$day_num."</td>"; } else { echo "<td bgcolor=#1a2e00><b><a href=\"".$_SERVER['PHP_SELF']."?Y=".date('Y')."&m=".date('m')."&d=0".$day_num."\" class=cal_links>".$day_num."</a></b></td>"; } } } Quote Link to comment Share on other sites More sharing options...
gluck Posted April 14, 2008 Share Posted April 14, 2008 Paste query and table structure. Quote Link to comment Share on other sites More sharing options...
gluck Posted April 14, 2008 Share Posted April 14, 2008 Your code is somewhat on the same lines... create link only when the date matches with the date in db. Quote Link to comment Share on other sites More sharing options...
ksduded Posted April 15, 2008 Author Share Posted April 15, 2008 Paste query and table structure. the query is $result = mysql_query("SELECT * from equatorhd"); The table structure is: prog_id int(5) No auto_increment prog_station varchar(15) latin1_swedish_ci No prog_timezone varchar(3) latin1_swedish_ci No prog_date date No prog_time time No prog_dur time No prog_endtime time No prog_programname varchar(250) latin1_swedish_ci No prog_episodename varchar(250) latin1_swedish_ci No prog_episodenum int(3) No prog_episodedesc text latin1_swedish_ci No prog_actors varchar(1) latin1_swedish_ci No prog_status varchar(1) latin1_swedish_ci No Quote Link to comment Share on other sites More sharing options...
ksduded Posted April 15, 2008 Author Share Posted April 15, 2008 ok i figured it out. It was much more complex than i had expected, but was mostly to do with the logic (while loops) rather than the use of the right query or syntax. Anyways, thanks for your help while ( $day_num <= $days_in_month ) { $result2= mysql_query("SELECT prog_date from equatorhd"); $recordfound = '0'; while($info1 = mysql_fetch_array($result2)) { $daydata = "2008-04-0".$day_num; if($info1['prog_date'] == $daydata) { echo "<td bgcolor=#1a2e00><b><a href=\"".$_SERVER['PHP_SELF']."?Y=".date('Y')."&m=".date('m')."&d=0".$day_num."\" class=cal_links>".$day_num."</a></b></td>"; recordfound= '1'; break; } } } if ($recordfound != '1') { echo "<td bgcolor=#264300>".$day_num."</td>"; } 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.