php搜索表单只显示选定的血型

时间:2015-03-25 14:12:03

标签: php mysql forms

我想在表格中仅显示选定的值数据,但此代码显示数据库中的所有数据如果选择了什么,但我只想选择数据请帮助我,如果可能我想在此代码中添加一个下拉列表专家帮助需要< / p>

<?php

$host="DBHOST";
$username="DBUSER";
$password="DBPASS";
$db_name="doners"; // create your own db
$tbl_name="doners";


mysql_connect("$host","$username","$password")or die("failed to connect to         db");
mysql_select_db("$db_name")or die("failed to select database");

if($_POST['bggroup']!="")

if($_POST['bggroup']!="")
$where='where bloodgroup='."'".$_POST['bggroup']."'";

 $sql = "select firstname, lastame, mobile, bloodgroup, city from $tbl_name    ".
 $where." order by firstname";
 $result = mysql_query($sql);



?>
<form id="form1" name="form1" method="post" action="">
  <table width="800" border="1" cellspacing="0" cellpadding="3">
<tr>
  <td colspan="2">Blood Group :

    <select  name='bggroup' id='bggroup' onchange="form1.submit();">
        <option value="" selected="selected" >Select</option>
        <OPTION VALUE="A +ve">A +ve </OPTION>
        <OPTION VALUE="A -ve">A -ve </OPTION>
        <OPTION VALUE="B +ve">B +ve </OPTION>
        <OPTION VALUE="B -ve">B -ve </OPTION>
        <OPTION VALUE="O +ve">O +ve </OPTION>
        <OPTION VALUE="O -ve">O -ve </OPTION>
        <OPTION VALUE="AB +ve">AB +ve </OPTION>
        <OPTION VALUE="AB -ve">AB -ve </OPTION>
      </select>

      <script language="JavaScript" type="text/javascript">
  var adv='<? echo $_POST['bggroup'] ?>';
  for(k=0;k<document.form1.bggroup.options.length;k++)
  {
    if(document.form1.bggroup.options[k].value==adv)
    {
        document.form1.bggroup.options[k].selected=true;
    }
  }
 </script>
  </td>
 </tr>
 <tr>
  <td align="center"><strong>First Name</strong></td>
  <td align="center"><strong>Last Name</strong></td>
  <td align="center"><strong>Mobile</strong></td>
  <td align="center"><strong>Blood Group</strong></td>
  <td align="center"><strong>City</strong></td>
</tr>
<?php
 while($rows=mysql_fetch_array($result))
{

?>
<tr>
  <td width="20%"align="center" ><?php echo $rows['firstname']; ?></td>
  <td width="20%" align="center"><?php echo $rows['lastame']; ?></td>
  <td width="20%" align="center"><?php echo $rows['mobile']; ?></td>
  <td width="20%" align="center"><?php echo $rows['bloodgroup']; ?></td>
  <td width="20%" align="center"><?php echo $rows['city']; ?></td>
</tr>
<?php
}
?>
</table>
</form>
<?php
mysql_close();
?>        

代码已结束

0 个答案:

没有答案