2015-10-25 33 views
0

我需要从下拉列表中获取值,并将它们查询到其他SQL命令中以将最终数据提取到表中。我有这个代码,但当点击提交按钮时,表中没有显示任何内容。事实上,桌子消失了,什么也没有显示出来。无法从下拉列表中获取值

  <?php 
require_once('../include/global.php'); 
?> 
<!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"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
</head> 
<body> 
<div class=""> 
<form action="" method="submit"> 
<select name="Date" required class="form-control" id="Date"> 
    <option value="">Please Select Date</option> 
    <?php $sql2="SELECT * FROM clinic.appoint GROUP BY date"; 
    $result2 = mysqli_query($con, $sql2) or die($sql2."<br/><br/>".mysql_error()); 
    while($rows2=mysqli_fetch_array($result2)){?> 
    <option value="<?php echo $rows2['date'] ?>"><?php echo $rows2['date'] ?></option> 
    <?php } ?> 
</select> 
<input type="submit" name="submit" value="Select Date" /> 
</form> 
<?php 
if(isset($_POST['submit'])){ 
      if(isset($_POST['Date'])){ 


      $selectOpt =$_REQUEST['Date']; 
$sql="SELECT * FROM clinic.appoint WHERE date='".$selectOpt."' "; 
$result = mysqli_query($con, $sql) or die($sql."<br/><br/>".mysql_error()); 
$rows=mysqli_fetch_array($result); 
} 
else{ 
     $sql."<br/><br/>".mysql_error(); 
} 
?> 
<table> 
<th>Time</th> 
<th>Name</th> 
<tr> 
<td><?php echo $rows['time'] ?></td> 
<td><?php echo $rows['name'] ?></td> 
</tr> 
</table> 
<?php } ?> 
</div> 
</body> 
</html> 
+0

你之后的HTML代码将PHP代码。在HTML之后不要放置PHP代码。在HTML之前放置PHP。 –

回答

1

只需复制并粘贴您的网页的完整代码,然后更改数据库信息

我认为它会为你工作

<?php 
define("DB_HOST", "db_host"); 
define("DB_USER", "db_user"); 
define("DB_PASSWORD", "db_pass"); 
define("DB_DATABASE", "db_name"); 
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD,DB_DATABASE); 
?> 
<script language="javascript" type="text/javascript"> 
var selectSearch = document.getElementById('Date').value; 

selectSearch.onchange = function() { 
    window.location = selectSearch[selectSearch.selectedIndex].value; 
}; 
</script> 
</head> 

<body> 
<div class="container12"> 
    <header> 
    <div align="center"> 
     <div class="column12"> <a href="homepage.php"><img src="images/logo.png"/></a> </div> 
    </div> 
    <div align="center"> 
      <div align="center"><a href="logout.php">Logout</a></div> 
    </div> 
    </header> 
    <h1 id="home">&nbsp;</h1> 
    <div class="alert"></div> 
    <div class="column12" align="left"><B><center>Appointments</B></center><br /> 
    </div> 
    </div> 
    </div> 
</div> 
<div class="container12" align="center"> 
<form action="addApp.php" method="post" name="form1" id="form1"> 
<table width="700px" class="imagetable" align="center"> 
<th align="center">Name</th> 
<th>Date</th> 
<th>Time</th> 
<th>Contact Number</th> 
<th>Action</th> 
<tr> 
<td><input type="text" name="name" class="large-fld-app" placeholder="name"/></td> 
<td><input type="text" name="date" class="large-fld-app" placeholder="DD/MM/YYYY"/></td> 
<td><input type="time" name="time" class="large-fld-app"/></td> 
<td><input type="text" name="phone" class="large-fld-app"/></td> 
<td align="center"><input type="submit" value="" name="submit" class="imgClass_save" /> 
</td> 
</tr> 
</table> 
</form> 
</div> 
<?php 
$sql="SELECT * FROM clinic.appoint"; 
$result = mysqli_query($con, $sql) or die($sql."<br/><br/>".mysql_error()); 
$rows=mysqli_fetch_array($result) 
?> 
<div class="container"> 
<table> 
      <thead> 
      <tr> 
          Schedule    

       <th scope="row"> 
        <form action="" method="submit"> 
        <select name="Date" required class="form-control" id="Date"> 
    <option value="">Please Select Date</option> 
    <?php $sql2="SELECT * FROM clinic.appoint"; 
    $result2 = mysqli_query($con, $sql2) or die($sql2."<br/><br/>".mysql_error()); 
    while($rows2=mysqli_fetch_array($result2)){?> 
    <option value="<?php echo $rows2['id'] ?>"><?php echo $rows2['name'] ?></option> 
    <?php } ?> 
</select> 
<input type="submit" name="submit" value="Select Date" /> 
</form> 
       </th> 
       <td class="schedule-offset" colspan="2"> 
       </td> 
      </tr> 
      </thead> 
      <tbody> 
      <?php if(isset($_REQUEST['submit'])){ ?> 
      <?php if(isset($_REQUEST['Date'])){ ?> 

      <?php 
      $selectOpt = $_REQUEST['Date']; 
      $sql="SELECT * FROM clinic.appoint WHERE date='".$selectOpt."' "; 
      $result = mysqli_query($con, $sql) or die($sql."<br/><br/>".mysql_error()); 

?> 
      <tr> 
      <?php while($rows=mysqli_fetch_array($result)){?> 
       <th scope="row"> 


       <?php echo $rows['time'] ?> 
       </th> 
       <td scope="row" id="scheduleDate"> 
       <?php echo $rows['name'] ?> 
       </td> 
       <td scope="row"> 
       <?php echo $rows['date'] ?> 
       </td> 
          <?php } ?> 

      </tr> 
      <tr> 
      <?php }?> 
      <?php }?> 
       <th scope="row"> 
       <time datetime="14:00">2:00 PM</time> 
       </th> 
       <td> 
       <a href="speakers.html#tessa-harmon"> 
        <h4>Tessa Harmon</h4> 
        Crafty Coding: Generating Knitting Patterns 
       </a> 
       </td> 
      </tr> 
      </tbody> 
     </table> 
</div> 


</body> 
</html> 
+0

查看我编辑的代码。没有显示在表中 – droidnation

+0

你可以给你的表格结构和一些样品数据,这就是为什么我可以检查它我自己(现在不需要) –

+0

给我你的电子邮件发送文件夹给你 – droidnation