我的php搜索代码有问题

时间:2016-03-27 06:53:33

标签: php

我不确定我的代码出了什么问题。我收到消息" Page不工作"不知道为什么?我正在尝试获取过滤器的详细信息" retrieve1.php"但是每当我尝试点击学生过滤器时,我都会收到一条消息,说“" Page不能正常工作"”。我很感激这里的任何帮助。



<?php

 echo "<body style='background-color:#DCDCDC'>";

include ("account.php");
( $db = mysql_connect( $hostname, $username, $password ))
    or die ( "unable to connect to MYSQL database" );
mysql_select_db( $project );



$sql= "SELECT * FROM bpi_registration LEFT JOIN 
bpi_schoolInfo on bpi_registration.id_school = bpi_schoolInfo.id_school";
	    

$query=mysql_query($sql) or die(mysql_error());



function grade()
{
	$query= "select distinct class_name from bpi_classInfo";
	$result=mysql_query($query) or  die(mysql_error());
		
		
	while  ($value = mysql_fetch_array ($result))
	{
	echo "<option value='" . $value['class_name'] . "'>" . $value['class_name'] . "</option>";
	}


}



function school()
{
	$query= "select distinct school_name from bpi_schoolInfo";
	$result=mysql_query($query)or  die(mysql_error());
		
		
	while  ($value = mysql_fetch_array ($result))
	{
		echo "<option value='" . $value['school_name'] . "'>" . $value['school_name'] . "</option>";
	}


}




function team()
{
	$query= "select distinct team_name from bpi_teamProfile";
	$result=mysql_query($query)or  die(mysql_error());
		
		
	while  ($value = mysql_fetch_array ($result))
	{
		echo "<option value='" . $value['team_name'] . "'>" . $value['team_name'] . "</option>";
	}


}



function students()
{
	$query= "select * from bpi_registration";
	$result=mysql_query($query)or  die(mysql_error());
		
		
	while  ($value = mysql_fetch_array ($result))
	{
		echo "<option value='" . $value['first_name'].' '.$value['last_name']. "'>" . $value['first_name'].' '.$value['last_name']. "</option>";
		
	}


}


?>



<form action="retrieve1.php" method="GET">

<select name="Grade">
<option value="" selected="selected">Choose Grade</option>
<?php grade() ?>
</select>

<select name="School">
<option value="" selected="selected">Choose School</option>
<?php school() ?>
</select>

<select name="Team">
<option value="" selected="selected">Choose Team</option>
<?php team() ?>
</select>

<select name="Students">
<option value="" selected="selected">Choose Students</option>
<?php students() ?>
</select>

<input type="submit" value="Find" />
</form>



<table width="600" border="2">  
<tr>  
<th width="91"> <div align="center">First Name </div></th>  
<th width="98"> <div align="center">Last Name </div></th>  
<th width="198"> <div align="center">Email </div></th>  
<th width="97"> <div align="center">City </div></th>  
<th width="97"> <div align="center">State </div></th>  
<th width="59"> <div align="center">Country </div></th>   
<th width="59"> <div align="center">View </div></th>   


<tr>

<?php
if (isset($_GET['Students']))
{
while ($row=mysql_fetch_array($query))
{ 


    echo $row['email'];
    echo $row['address_city'];
    echo $row['address_state'];
    echo $row['address_country'];
  

  }




}


?>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

您在select上编写了错误的代码。使用下面的一个。

<form action="retrieve1.php" method="GET">

<select name="Grade">
<option value="" selected="selected">Choose Grade</option>
<?php grade() ?>
</select>

<select name="School">
<option value="" selected="selected">Choose School</option>
<?php school() ?>
</select>

<select name="Team">
<option value="" selected="selected">Choose Team</option>
<?php team() ?>
</select>

<select name="Students">
<option value="" selected="selected">Choose Students</option>
<?php students() ?>
</select>

<input type="submit" value="Find" />
</form>

并且你缺少大括号的大括号结束

<?php
if (isset($_GET['Students']))
{
    while ($row=mysql_fetch_array($query))
    {
        echo $row['email'];
        echo $row['address_city'];
        echo $row['address_state'];
        echo $row['address_country'];
    }
}
?>

答案 1 :(得分:0)

您缺少}

<?php
if (isset($_GET['Students']))
{
    while ($row=mysql_fetch_array($query))
    {
        echo $row['email'];
        echo $row['address_city'];
        echo $row['address_state'];
        echo $row['address_country'];
    }
}
?>