Forum Moderators: coopster

Message Too Old, No Replies

Manipulation

         

Imy_S3

10:04 am on Feb 17, 2004 (gmt 0)

10+ Year Member



Got the .php file below.

It asks the user to select the option, if its in the database it will display the results.

however, when displaying the results, the form is displayed again.
if the results are in the database all i want is just the results not the form as well.

how do i get it to do this.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Page title</title>
</head>

<body>

<p>Please select the type of shop you are looking for</p>

<form action="shopping.php" method="post">

<input type =radio name=option checked value='sports'>
sports <br>

<input type =radio name=option value='shoes'>
Shoes<br>

<input type =radio name=option value='hats'>
Hats<br>

<input type= radio name=option value='clothes'>
clothes<br>

<input type =radio name=option value='jewellery'>
Jewellery <br>

<input type =radio name=option value='cards'>
Cards<br>

<input type =radio name=option value='general'>
General<br>

<input type = submit name= submit1>
<input type = reset value="Clear Form" >

<a href="storeDirectory.html">Store Directory</a>
</form>

<?
if (isset($_POST['submit1']))
{
//Connection to Database
$dbcon=pg_connect("host=db port=5 dbname=blah user=blah password=blah");

SQL statement looking for information in the database
$sql="SELECT * FROM shop1 WHERE shoptype = '$_POST[option]'";

//Prints the SQL statement
echo $sql;

//Stores the result of the SQL statement
$result = pg_exec($sql);

//Returns the number of rows in the result
$nrows = pg_numrows($result);

if($nrows!= 0)
{
print "<p>Your search for " . $_POST[option] . " has the following results </p>";
print "<table border=20>
<tr>
<th>Name
<th>Address Line One
<th>Address Line Two
<th>County
<th>Postcode
<th>Telephone Number
<th>Fax Number
<th>Email
<th>Web Site\n";

for($j=0; $j<$nrows; $j++)
{

$row = pg_fetch_array ($result);

printf ("<tr><td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>", $myrow['shopname'], $myrow['shopaddresslineone'], $myrow['shopaddresslinetwo'], $myrow['shopcounty'], $myrow['shoppostcode'], $myrow['shoptelephone'], $myrow['shopfax'], $myrow['shopemail'], $myrow['shopwebsite']);

print "<tr><td>" . $row["shopname"];
print "<td>" . $row["shopaddresslineone"];
print "<td>" . $row["shopaddresslinetwo"];
print "<td>" . $row["shopcounty"];
print "<td>" . $row["shoppostcode"];
print "<td>" . $row["shoptelephone"];
print "<td>" . $row["shopfax"];
print "<td>" . $row["shopemail"];
print "<td>" . $row["shopwebsite"];
print "\n";
}
print "</table>\n";
}

}
else
{
echo "<p>Name:</p>\n";
}
?>

</body>
</html>

Netizen

3:11 pm on Feb 17, 2004 (gmt 0)

10+ Year Member



You could try something along the lines of:

$showForm=true;

if (isset($_POST['submit1'])) {

...

if($nrows!= 0) {

...

$showForm=false;

}

...

}

if ($showForm) {

// print form here

}

...