我創建了一個連接到mysql的日曆。日曆搜索mysql並顯示在休息時間的員工數量。有幾個經理爲各種各樣的僱員。我創建了一個searchterm框,管理員可以在其中鍵入名稱,代碼將查詢特定於管理員名稱的數據庫(實質上只顯示經理員工而不是整個公司)。僱員休假時間的數量在日曆內顯示爲鏈接和該特定日期的總數。一旦點擊它,然後顯示與當天關聯的員工姓名。我們遇到的問題是,經理點擊鏈接後,它會自動默認爲所有員工,而不是特定於經理的員工。經理人的搜索字詞正在被刪除,代碼默認回覆,就像沒有輸入任何內容。我的問題是,我如何可以重複使用該searchterm,直到其他明智的指示。PHP,Mysql日曆
$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 '<div id="button">';
echo "<a href='".$_SERVER['PHP_SELF']."?month=".$monthstring."&day=".$i."&year=".$year. "&v=false ' >".$num_rows."</a></td>";
echo '</div>';
}
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 '<div id="button">';
echo "<a href='".$_SERVER['PHP_SELF']."?month=".$monthstring."&day=".$i."&year=".$year."&v=true' >".$num_rows."</a></td>";
echo '</div>';
$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 '<div id="button">';
echo "<a href='".$_SERVER['PHP_SELF']."?month=".$monthstring."&day=".$i."&year=".$year."&v=true' >".$num_rows."</a></td>";
echo '</div>';
}
}
echo "<tr>";
echo"</table>";
?>
<div class="accordion vertical">
<ul>
<li>
<input type="radio" id="radio-3" name="radio-accordion" />
<label for="radio-3">Time Off by Driver Code</label>
<div class="content">
<?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']."</br>";
}
}
else {
echo "";
}
?>
<?php
echo "<tr >";
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']."</br>";
}
}
else {
echo "";
}
echo "<tr>";
var_dump($searchTerm);
?>
請,或不使用'mysql_ *'功能(HTTP: //stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php),他們不再維護和[正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。學習[準備的語句](http://en.wikipedia.org/wiki/Prepared_statement),並使用[PDO](http://us1.php.net/pdo)或[MySQLi](http:// us1.php.net/mysqli)。你也會想[防止SQL注入!](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – 2014-11-20 19:19:38