Jump to content

[SOLVED] My numb brain can't handle this


ksduded

Recommended Posts

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>"; 
	}
              }
}

Link to comment
https://forums.phpfreaks.com/topic/101096-solved-my-numb-brain-cant-handle-this/
Share on other sites

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               

 

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>";
}

Archived

This topic is now archived and is closed to further replies.

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