试图从我桌子上的下拉列表中查看信息

时间:2015-03-13 13:38:10

标签: php jquery html

我有两页。一个包含我的分支下拉列表,而第二个是我的php连接页面 我想从下拉列表中选择一个分支,单击进程,然后表格显示分支名称,状态,金额和日期2 每当点击过程,我得到一个只有标题的空表 这是我的代码:

branch.php

<html>
<body>
<br><br><br>
<form method = "POST" action = "getuser.php" >
<select name="branch">
  <option value="">Select a branch:</option>
  <option value="1">Maths</option>
  <option value="3">English</option>
  <option value="4">Biology</option>
  <option value="5">Chemistry</option>
  <option value="6">Economics</option>
  </select>
  <br><br>
  <input type = "submit" name "submit" value ="Process">
</form>
<br>

 

getuser.php

<?php
//$q = intval($_GET['q']);

$con = mysqli_connect('localhost','root','','modem');
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}
    if(!isset($_POST['submit'])) {

        $branch = $_POST['branch'];

        $result = mysqli_query($con,"SELECT *, DATE_FORMAT( date, '%M %Y' )as date2
        FROM bm_ibadan_division
        WHERE branch = '$branch'
        ORDER BY date ASC");

        echo "<table align='center'  width='400px' border='1'>
        <tr>
        <th>Branch</th>
        <th>Status</th>
        <th>Amount</th>
        <th>Date2</th>
        </tr>";

         while($row = mysqli_fetch_array($result)) {
          echo "<tr>";
          echo "<td>" . $row['branch'] . "</td>";
          echo "<td>" . $row['status'] . "</td>";
          echo "<td>" . $row['amount'] . "</td>";
          echo "<td>" . $row['date2'] . "</td>";
          echo "</tr>";
        }

        echo "</table>";
    } else echo "access denied";
        mysqli_close($con);


?>

1 个答案:

答案 0 :(得分:0)

$con = mysql_connect('localhost','root','','modem');

如果(!$ CON)     死(&#39;无法连接:&#39; .mysql_error($ con));

if(isset($ _ POST [&#39; submit&#39;])){

    $branch = $_POST['branch'];

    $result = mysql_query($con,"SELECT *, DATE_FORMAT( date, '%M %Y' )as date2 FROM bm_ibadan_division WHERE branch = $branch ORDER BY date ASC");

    echo "<table align='center'  width='400px' border='1'>
    <tr>
    <th>Branch</th>
    <th>Status</th>
    <th>Amount</th>
    <th>Date2</th>
    </tr>";

     while($row = mysql_fetch_array($result)) {
      echo "<tr>";
      echo "<td>" . $row['branch'] . "</td>";
      echo "<td>" . $row['status'] . "</td>";
      echo "<td>" . $row['amount'] . "</td>";
      echo "<td>" . $row['date2'] . "</td>";
      echo "</tr>";
    }

    echo "</table>";
} 
else
{
    echo "access denied"; 
}

mysqli_close($con);