2016-03-03 45 views
-1

當「A」用戶選擇他的抵達日期並自動從當前日期的下拉列表中顯示當天的可用停車位時,我想執行此功能。根據所選日期顯示下拉列表中的可用選項

例如,「A」用戶選擇停車位號碼。 001 2016年4月3日。因此,對於下一個想要預訂的用戶而言,當天不再能夠預留該停車位&必須選擇其他可用停車位。 問題是如何刪除特定日期的預留停車位?

下面是我的數據庫表:

student_info(
    `Student_ID` varchar(9) NOT NULL, 
    `Password` varchar(15) NOT NULL, 
    `Email_Address` varchar(30) NOT NULL, 
    `Contact_No` int(10) NOT NULL, 
    `StudentID_Expiry` date NOT NULL, 
    `Course` varchar(100) NOT NULL, 
    `Full_Name` varchar(50) NOT NULL, 
    `IC_Passport_No` varchar(30) NOT NULL, 
    `BirthDate` date NOT NULL, 
    `Gender` varchar(6) NOT NULL, 
    `Nationality` varchar(30) NOT NULL, 
    `Address` varchar(30) NOT NULL, 
    `City` varchar(30) NOT NULL, 
    `State` varchar(15) NOT NULL, 
    `Postcode` int(5) NOT NULL 
) 

students_reservation(
    `Reservation_Date` date NOT NULL, 
    `Reservation_ID` varchar(6) NOT NULL, 
    `Arrival_Date` date NOT NULL, 
    `Student_ID` varchar(9) NOT NULL, 
) 

**我需要創建另一個數據庫表的停車位是可用於所有的日期?

我試圖在Dreamweaver CS6中做這個功能,但我沒有任何想法如何開始在PHP中編寫代碼,因爲我仍然是初學者。

任何人都可以幫助我嗎?謝謝

下面是我的代碼:

<?php require_once('Connections/oprs.php'); ?> 
<?php 
//initialize the session 
if (!isset($_SESSION)) { 
    session_start(); 
} 

// ** Logout the current user. ** 
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true"; 
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){ 
    $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']); 
} 

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){ 
    //to fully log out a visitor we need to clear the session varialbles 
    $_SESSION['MM_Username'] = NULL; 
    $_SESSION['MM_UserGroup'] = NULL; 
    $_SESSION['PrevUrl'] = NULL; 
    unset($_SESSION['MM_Username']); 
    unset($_SESSION['MM_UserGroup']); 
    unset($_SESSION['PrevUrl']); 

    $logoutGoTo = "Logout_OPRS.php"; 
    if ($logoutGoTo) { 
    header("Location: $logoutGoTo"); 
    exit; 
    } 
} 
?> 
<?php 
if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
    if (PHP_VERSION < 6) { 
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
    } 

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

    switch ($theType) { 
    case "text": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break;  
    case "long": 
    case "int": 
     $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
     break; 
    case "double": 
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
     break; 
    case "date": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break; 
    case "defined": 
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
     break; 
    } 
    return $theValue; 
} 
} 

$colname_DisplayID = "-1"; 
if (isset($_GET['Student_ID'])) { 
    $colname_DisplayID = $_GET['Student_ID']; 
} 
mysql_select_db($database_oprs, $oprs); 
$query_DisplayID = sprintf("SELECT * FROM student_info WHERE Student_ID = %s", GetSQLValueString($colname_DisplayID, "text")); 
$DisplayID = mysql_query($query_DisplayID, $oprs) or die(mysql_error()); 
$row_DisplayID = mysql_fetch_assoc($DisplayID); 
$totalRows_DisplayID = mysql_num_rows($DisplayID); 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/OPRS_Template.dwt" codeOutsideHTMLIsLocked="false" --> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<!-- InstanceBeginEditable name="doctitle" --> 
<title>Reserve Parking | Online Parking Reservation</title> 
<link rel="shortcut icon" href="picture/shortcut.png"/> 
<!-- InstanceEndEditable --> 
<!-- InstanceBeginEditable name="head" --> 
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
    <script src="//code.jquery.com/jquery-1.10.2.js"></script> 
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
    <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> 
    <script src="SpryAssets/SpryValidationPassword.js" type="text/javascript"></script> 
    <script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script> 
    <link rel="stylesheet" href="/resources/demos/style.css"> 
    <script> 
    $(function() { 
    $("#arrivaldate").datepicker({ 
     changeMonth: true, 
     changeYear: true, 
     dateFormat: "yy-mm-dd", 
     minDate:0 
    }); 
    }); 
    </script> 
<!-- InstanceEndEditable --> 
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script> 
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" /> 
</head> 

<body> 
<div class="logo"> 
    <div align="center"><!-- InstanceBeginEditable name="EditRegion4" --> 
    <table width="1013" border="0"> 
     <tr> 
     <td colspan="11"><img src="picture/thinlongbar.png" width="1017" height="5" alt="longbar" /></td> 
     </tr> 
     <tr> 
     <td width="114"><div align="center"><a href="<?php echo $logoutAction ?>"><img src="picture/logout.png" width="111" height="34" alt="logout" /></a></div></td> 
     <td width="3">&nbsp;</td> 
     <td width="3">&nbsp;</td> 
     <td width="3">&nbsp;</td> 
     <td width="3">&nbsp;</td> 
     <td width="636"><img src="picture/logo.png" width="596" height="100" alt="logo" /></td> 
     <td width="1">&nbsp;</td> 
     <td width="3">&nbsp;</td> 
     <td width="3">&nbsp;</td> 
     <td width="3">&nbsp;</td> 
     <td width="205"><ul id="MenuBar2" class="MenuBarHorizontal"> 
      <li><a class="MenuBarItemSubmenu" href="#"><strong>Hi, <?php echo $_SESSION['MM_Username']; ?>!</strong></a> 
      <ul> 
       <li> 
       <div align="left"><strong><a href="PersonalInfo_OPRS.php">My Profile</a></strong></div> 
       </li> 
       <li> 
       <div align="left"><strong><a href="MyReservation_OPRS.php">My Parking Reservation</a></strong></div> 
       </li> 
</ul> 
      </li> 
</ul></td> 
     </tr> 
     <tr> 
     <td colspan="11"><img src="picture/thinlongbar.png" width="1017" height="5" alt="longbar" /></td> 
     </tr> 
    </table> 
    <!-- InstanceEndEditable --></div> 
    <!-- InstanceBeginEditable name="EditRegion5" --> 
    <div align="center"> 
    <table width="1013" border="0"> 
     <tr> 
     <td width="1349"><ul id="MenuBar1" class="MenuBarHorizontal"> 
      <li> 
      <div align="center"><a href="Afterlogin_OPRS.php"><strong>Home</strong></a></div> 
      </li> 
      <li> 
      <div align="center"><strong><a href="ParkingRate(A.L).php">Parking Rate</a></strong></div> 
      </li> 
      <li> 
      <div align="center"><strong><a href="ReserveParking(A.L).php">Reserve Parking</a></strong></div> 
      </li> 
      <li> 
      <div align="center"><a href="FAQ(A.L).php"><strong>FAQ</strong></a></div> 
      </li> 
      <li> 
      <div align="center"><strong><a href="Feedback(A.L).php">Feedback</a></strong></div> 
      </li> 
     </ul></td> 
     </tr> 
    </table> 
    </div> 
    <!-- InstanceEndEditable --> 
    <div align="center"> 
    <table width="200" border="0"> 
     <tr> 
     <td><img src="picture/thinlongbar.png" width="1017" height="5" alt="longbar" /></td> 
     </tr> 
     <tr> 
     <td><img src="picture/parkingbanner.png" width="1015" height="115" alt="banner" /></td> 
     </tr> 
     <tr> 
     <td><img src="picture/thinlongbar.png" width="1017" height="5" alt="longbar" /></td> 
     </tr> 
    </table> 
    </div> 
</div> 
<!-- InstanceBeginEditable name="EditRegion3" --> 
<div align="center"> 
    <h1>RESERVE PARKING</h1> 
    <table width="723" border="0"> 
    <tr> 
     <td width="240" height="55"><div align="center"> <strong> Select Arrival Date &amp; Parking Spot</strong>  </div></td> 
     <td width="92"><div align="center"><img src="picture/arrow2.png" width="92" height="51" alt="arrow" /></div></td> 
     <td width="217"><div align="center">Confirm Reservation Information</div></td> 
     <td width="92"><div align="center"><img src="picture/arrow2.png" width="92" height="51" alt="arrow" /></div></td> 
     <td width="60"><div align="center">Success</div></td> 
    </tr> 
    </table> 
<br /> 

    <form id="form1" name="form1" method="post" action=""> 
    <table width="411" border="1"> 
     <tr> 
     <td width="219"><div align="right"><strong>Arrival Date :</strong></div></td> 
     <td width="176"><input type="text" name="arrivaldate" id="arrivaldate" /></td> 
     </tr> 
     <tr> 
     <td><div align="right"><strong>Available Parking Spot :<br /> 
      (<a href="#Parking">Refer to the Parking Maps</a>)</strong></div></td> 
     <td><select name="parkingspot" id="parkingspot"> 
      <option value="001">001</option> 
      <option value="002">002</option> 
      <option value="003">003</option> 
      <option value="004">004</option> 
      <option value="005">005</option> 
      <option value="006">006</option> 
      <option value="007">007</option> 
      <option value="008">008</option> 
      <option value="009">009</option> 
      <option value="010">010</option> 
      <option value="011">011</option> 
      <option value="012">012</option> 
      <option value="013">013</option> 
      <option value="014">014</option> 
      <option value="015">015</option> 
      <option value="016">016</option> 
      <option value="017">017</option> 
      <option value="018">018</option> 
      <option value="019">019</option> 
      <option value="020">020</option> 
     </select></td> 
     </tr> 
     <tr> 
     <td colspan="2"><div align="center"> 
      <input type="submit" name="btnreserve" id="btnreserve" value="Reserve" /> 
     </div></td> 
     </tr> 
    </table> 
    </form> 
    <h2><script type="text/javascript"> 
var MenuBar2 = new Spry.Widget.MenuBar("MenuBar2", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"}); 
</script><strong><a name="Parking" id="Parking"></a>Parking Maps:</strong></h2> 
    <table width="200" border="0"> 
    <tr> 
     <td><img src="picture/maps.png" width="839" height="533" alt="maps" /></td> 
    </tr> 
    </table> 
    <br /> 
</div><!-- InstanceEndEditable --> 
<div class="column"> 
    <div align="center"> 
    <table width="1023" border="0"> 
     <tr> 
     <td colspan="5"><img src="picture/thinlongbar.png" width="1017" height="5" alt="longbar" /></td> 
     </tr> 
     <tr> 
     <td width="266"><p align="center"><img src="picture/contact.png" width="43" height="43" alt="col1" />CONTACT US</p> 
      <p align="center">Email: [email protected]</p> 
     <p align="center">Tel No: 03 - 34826391</p></td> 
     <td width="7"><img src="picture/straightbar.png" width="5" height="142" alt="bar2" /></td> 
     <td width="402"><p align="center"><img src="picture/location.png" width="50" height="43" alt="col2" />OUR LOCATION (WALK - IN INQUIRY)</p> 
     <p align="center">STUDENT DEPARTMENT<br />Address<br />Address</p></td> 
     <td width="5"><img src="picture/straightbar.png" width="5" height="142" alt="bar2" /></td> 
     <td width="321"><p align="center"><img src="picture/payment.png" width="47" height="47" alt="col3" />PAYMENT (ONLY CASH)</p> 
     <p align="center">BURSARY DEPARTMENT<br />Address,<br />Address</p></td> 
     </tr> 
     <tr> 
     <td colspan="5"><img src="picture/thinlongbar.png" width="1017" height="5" alt="longbar" /></td> 
     </tr> 
    </table> 
    </div> 
</div> 
<div class="footer"> 
    <div align="center"> 
    <table width="398" border="0"> 
     <tr> 
     <td><div align="center">©2016 OPRS By University. All Rights Reserved. </div></td> 
     </tr> 
     <tr> 
     <td><img src="picture/thinlongbar.png" width="1017" height="5" alt="longbar" /></td> 
     </tr> 
    </table> 
    </div> 
</div> 
<script type="text/javascript"> 
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../SpryAssets/SpryMenuBarRightHover.gif"}); 
</script> 
</body> 
<!-- InstanceEnd --></html> 
<?php 
mysql_free_result($DisplayID); 
?> 
+0

歡迎來到Stack Overflow。我們需要看到一些HTML,PHP和JS代碼能夠提供幫助。請修改您的帖子並提供更多詳細信息。 – Twisty

+0

@Twisty我hv編輯我的帖子 –

回答

0

你正在嘗試做的是級聯多個選擇HTML元素。要做到這一點,你需要依靠js。

以下fiddle包含一個工作示例。

<form name="myform" id="myForm"> 
<select name="optone" id="stateSel" size="1"> 
    <option value="" selected="selected">Select state</option> 
</select> 
<br> 
<br> 
<select name="opttwo" id="countySel" size="1"> 
    <option value="" selected="selected">Please select state first</option> 
</select> 
<br> 
<br> 
<select name="optthree" id="citySel" size="1"> 
    <option value="" selected="selected">Please select county first</option> 
</select> 

var stateObject = { 
    "California": { 
     "Monterey": ["Salinas", "Gonzales"], 
     "Alameda": ["Berkeley"] 
    }, 
    "Oregon": { 
     "Douglas": ["Roseburg", "Winston"], 
    } 
} 
window.onload = function() { 
    var stateSel = document.getElementById("stateSel"), 
     countySel = document.getElementById("countySel"), 
     citySel = document.getElementById("citySel"); 
    for (var state in stateObject) { 
     stateSel.options[stateSel.options.length] = new Option(state, state); 
    } 
    stateSel.onchange = function() { 
     countySel.length = 1; // remove all options bar first 
     citySel.length = 1; // remove all options bar first 
     if (this.selectedIndex < 1) { 
      countySel.options[0].text = "Please select state first" 
      citySel.options[0].text = "Please select county first" 
      return; // done 
     } 
     countySel.options[0].text = "Please select county" 
     for (var county in stateObject[this.value]) { 
      countySel.options[countySel.options.length] = new Option(county, county); 
     } 
     if (countySel.options.length==2) { 
      countySel.selectedIndex=1; 
      countySel.onchange(); 
     } 

    } 
    stateSel.onchange(); // reset in case page is reloaded 
    countySel.onchange = function() { 
     citySel.length = 1; // remove all options bar first 
     if (this.selectedIndex < 1) { 
      citySel.options[0].text = "Please select county first" 
      return; // done 
     } 
     citySel.options[0].text = "Please select city" 

     var cities = stateObject[stateSel.value][this.value]; 
     for (var i = 0; i < cities.length; i++) { 
      citySel.options[citySel.options.length] = new Option(cities[i], cities[i]); 
     } 
     if (citySel.options.length==2) { 
      citySel.selectedIndex=1; 
      citySel.onchange(); 
     } 

    } 
} 

最後,讓它爲你工作,你可以創建這些stateObject陣列呼應你的PHP數組變量,並將其格式化成JSON。

+0

,但首先我必須讓用戶選擇日期第一,這意味着我將使用jquery的日期選擇器爲那麼只有我會插入選擇選項供用戶選擇可用該日期的選項。那我該怎麼做呢?和urs一樣嗎? –

+0

@ U.K.N是的,你可以用我鏈接你的例子做到這一點,但這不是唯一的方法。也許更好的解決方案是:1.用jQuery檢測日期變化; 2.撥打ajax電話以獲取選定日期的可用停車位列表。 Google:PHP和AJAX。這很容易,你會愛上它。還需要弄清楚如何在運行中更改選擇選項(大多數組件都以自己的方式進行操作)。 – Bramastic

+0

您是否知道如何從選擇的下拉列表中刪除選定的選項?就像你的例子一樣,在第一個選項中,我從STATE選項中選擇了「California」,然後選擇第二個選項「monterey」。一旦我點擊提交按鈕,如何從第二個選項刪除「monterey」?所以在此之後,當我從第一選項中選擇加利福尼亞州時,「蒙特雷」已經從第二選項中刪除 –

相關問題