php,mysql,calendar

I have created a calendar which is connected to mysql. The calendar searches mysql and shows the number of employees on timeoff. There are several managers for a variety of employees. I created a searchterm box at which the manager can type there name and the code will query the database specific to the managers name (essentially only showing that managers employees instead of the whole company). The number of employees on time off are shown inside the calendar as a link which is also total number of employees off for that specific day. Once clicked it then shows the employee names associated with the day. The problem im having is once the manager clicks onto the link, it automatically defaults to all employees instead of the ones specific to the manager. The search term does run once and shows the results for the present day but nothing else. The managers search term is getting dropped and the code is defaulting back as if nothing was entered. My question is how I can reuse that searchterm over and over again until other wise directed. Here is my code:

[php]$searchTerm = trim($_GET[‘keyname’]);

if( $searchTerm != ‘All Drivers’ && $searchTerm != ‘’)

{
$sqlEvent2 = mysql_query(“select * FROM timeoff_365_days where (DM = ‘$searchTerm’ or FM = ‘$searchTerm’ or region =’$searchTerm’ or location =’$searchTerm’) and TimeOffDate = '”.$year."-".$month."-".$i."’");
$num_rows = mysql_num_rows($sqlEvent2);

echo ‘

’;
echo “<a href=’”.$_SERVER[‘PHP_SELF’]."?month=".$monthstring."&day=".$i."&year=".$year. “&v=false ’ >”.$num_rows."";
echo ‘
’;

}
else{

$sqlEvent = mysql_query( “select * FROM timeoff_365_days where TimeOffDate = '”.$year."-".$month."-".$i."’" );
if (!$sqlEvent) {
echo 'Could not run query: ’ . mysql_error();
exit;
}

$num_rows = mysql_num_rows($sqlEvent);
echo ‘

’;
echo “<a href=’”.$_SERVER[‘PHP_SELF’]."?month=".$monthstring."&day=".$i."&year=".$year."&v=true’ >".$num_rows."";
echo ‘
’;

$sqlEvent = mysql_query( “select * FROM timeoff_365_days where TimeOffDate = '”.$year."-".$month."-".$i."’" );
if (!$sqlEvent) {
echo 'Could not run query: ’ . mysql_error();
exit;
}

$num_rows = mysql_num_rows($sqlEvent);
echo ‘

’;
echo “<a href=’”.$_SERVER[‘PHP_SELF’]."?month=".$monthstring."&day=".$i."&year=".$year."&v=true’ >".$num_rows."";
echo ‘
’;

}

}

echo “

”;
echo"";
?>
  • Time Off by Driver Code
    <?php if(($_GET['v']==false)) { $sqlEvent2 = "select * FROM timeoff_365_days where (DM = '$searchTerm' or FM = '$searchTerm' or region ='$searchTerm'or location ='$searchTerm') and TimeOffDate ='".$year."/".$month."/".$day."'"; $resultEvents2 = mysql_query($sqlEvent2); while ($events2 = mysql_fetch_array($resultEvents2)){ echo $events2['DriverCode']."-"; echo $events2['Unit'].""; } } else { echo ""; } ?> <?php echo ""; var_dump($searchTerm); if(isset($_GET['v'])) { $sqlEvent = "select * FROM timeoff_365_days where TimeOffDate ='".$year."/".$month."/".$day."'"; $resultEvents = mysql_query($sqlEvent); while ($events = mysql_fetch_array($resultEvents)){ echo $events['DriverCode']."-"; echo $events['Unit'].""; } } else { echo ""; } echo " "; var_dump($searchTerm); ?>[/php]

Is ‘v’ being set in the url? If it is, the last query will loop through with no search term.

Check to see the $_GET[‘v’] condition is meeting your expectations in the last two queries.

Sponsor our Newsletter | Privacy Policy | Terms of Service