PDA

View Full Version : data appear before searching


razaksamad
02-14-2008, 09:21 AM
this a working scripts..but it appear mysql data before searching...anybody can help me how to hide mysql data and appear mysql data after searching only:confused:



<form name="form1" method="post" action="<?php $PHP_SELF; ?>"><a>Nationality Searching</a>
<input type="text" name="search" size=30 maxlength=30>
<input type="Submit" name="Submit" value="Submit">
</form>
<form><a>Example: Malaysia</a></form>
<form name="form2" method="post" action="logout_admin.php">
<div align="center">
<label><a href="admin_utama.php">Back to main menu</a><b><b><a>or</a>
<input name="Logout" type="submit" value="Logout">

</label>
</div>
</form>
</center></p>

<table>
<div align="center" class="style1">
<?php
function a(){
$search=$_POST["search"];

$result = mysql_query("SELECT * FROM alumni WHERE nationality LIKE '%$search%'");
return $result;
}?>

<?php
$b=a();
while($row=mysql_fetch_array($b))
{
$id=$r["id"];
$title=$row["title"];
$name=$row["name"];
$nationality=$row["nationality"];
$state=$row["state"];
$company=$row["company"];
$address=$row["address"];
$phone1=$row["phone1"];
$fax=$row["fax"];
$phone2=$row["phone2"];
$email=$row["email"];
$year=$row["year"];
$degree=$row["degree"];
$bachelor=$row["bachelor"];
$masterphd=$row["masterphd"];
$date=$row["date"];
$time=$row["time"];

?>

<table border="1" align="center" cellspacing="1">
<tr>

<th width="50">Title: </th>
<th width="400">Name: </th>
<th width="400">Nationality: </th>
<th width="400">State: </th>
<th width="400">Company: </th>
<th width="400">Address: </th>
<th width="400">Phone1: </th>
<th width="400">Fax: </th>
<th width="400">Phone2: </th>
<th width="250">Email: </th>
<th width="400">Year: </th>
<th width="400">Degree: </th>
<th width="400">Field of Study: </th>
<th width="400">Master/Phd: </th>
<th width="50">Date/Time: </th>
<tr>


<td><div align="center"><?php echo "$title"; ?></div></td>
<td><div align="center"><?php echo "$name"; ?></div></td>
<td><div align="center"><?php echo "$nationality"; ?></div></td>
<td><div align="center"><?php echo "$state"; ?></div></td>
<td><div align="center"><?php echo "$company"; ?></div></td>
<td><div align="center"><?php echo "$address"; ?></div></td>
<td><div align="center"><?php echo "$phone1"; ?></div></td>
<td><div align="center"><?php echo "$fax"; ?></div></td>
<td><div align="center"><?php echo "$phone2"; ?></div></td>
<td><div align="center"><?php echo "$email"; ?></div></td>
<td><div align="center"><?php echo "$year"; ?></div></td>
<td><div align="center"><?php echo "$degree"; ?></div></td>
<td><div align="center"><?php echo "$bachelor"; ?></div></td>
<td><div align="center"><?php echo "$masterphd"; ?></div></td>
<td><?php echo "$date $time<br>"; ?></td>
</tr>
<?php
}
?>

Andrew Johnson
02-14-2008, 01:50 PM
To check if a form has been posted you can use this:


if ($_SERVER["REQUEST_METHOD"] == "POST")


Just put all the display code inside of that IF statement.