Forum Moderators: coopster

Message Too Old, No Replies

Cant get values out of Database php

Cant get values out of Database php

         

Imy_S3

11:39 pm on Feb 29, 2004 (gmt 0)

10+ Year Member



Hi

I do a search for type of restaurant.

If it has not got it in the database it says no here and lets user look for another - this works fine.

However, when it is in the database it just displays the empty table (but i no the info is there)

cant seem to fing the problem

Can anyone help?

thanks in advance

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

<html>

<head>
<title>Resturants</title>
</head>

<body>

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

<?

$showForm=true;
if (isset($_POST['submit2']))
{

//Connection to Database
$dbcon=pg_pconnect("host=dbh port=5432 dbname=jkjkji user=ujkjkjkj password=jhjhjhh");

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

echo "$_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)
{
$showForm=false;
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['eatingName'], $myrow['eatingAddressLineOne'], $myrow['eatingAddressLineTwo'], $myrow['eatingCounty'], $myrow['eatingPostCode'], $myrow['eatingTelephone'], $myrow['eatingFax'], $myrow['eatingEmail'], $myrow['eatingWebSite']);

print "<tr><td>" . $row["eatingName"];
print "<td>" . $row["eatingAddressLineOne"];
print "<td>" . $row["eatingAddressLineTwo"];
print "<td>" . $row["eatingCounty"];
print "<td>" . $row["shoppostcode"];
print "<td>" . $row["shoptelephone"];
print "<td>" . $row["shopfax"];
print "<td>" . $row["eatingEmail"];
print "<td>" . $row["eatingWebSite"];
print "\n";
}
print "</table>\n";
}
else
{
print "<p>No Entry for " . $_POST[option]. "Please select another";
pg_close($dbcon);
$showForm=true;
}

}
if($showForm)
{

echo ( '<form action="eatSearch.php" method="post">' );

echo "<input type =radio name=option value='american'>";
echo ( 'American <br>' );

echo "<input type =radio name=option value='british'>";
echo ( 'British <br>' );

echo "<input type =radio name=option value='caribbean'>";
echo ( 'Caribbean<br>' );

echo "<input type =radio name=option value='chinese'>";
echo ( 'Chinese<br>' );

echo "<input type =radio name=option value='cuban'>";
echo ( 'Cuban <br>' );

echo "<input type =radio name=option value='english'>";
echo ( 'English<br>' );

echo "<input type =radio name=option value='french'>";
echo ( 'French<br>' );

echo "<input type =radio name=option value='latin'>";
echo ( 'Latin<br>' );

echo "<input type =radio name=option value='greek'>";
echo ( 'greek<br>' );

echo "<input type =radio name=option value='indian'>";
echo ( 'Indian<br>' );

echo "<input type =radio name=option value='irish'>";
echo ( 'Irish<br>' );

echo "<input type =radio name=option value='japanese'>";
echo ( 'Japanese<br>' );

echo "<input type =radio name=option value='italian'>";
echo ( 'Italian<br>' );

echo "<input type =radio name=option value='malaysian'>";
echo ( 'Malaysian<br>' );

echo "<input type =radio name=option value='mediterranean'>";
echo ( 'Mediterranean<br>' );

echo "<input type =radio name=option value='mongolian'>";
echo ( 'Mongolian<br>' );

echo "<input type =radio name=option value='oriental'>";
echo ( 'Oriental<br>' );

echo "<input type =radio name=option value='portuguese'>";
echo ( 'Portuguese<br>' );

echo "<input type =radio name=option value='spanish'>";
echo ( 'Spanish<br>' );

echo "<input type =radio name=option value='thai'>";
echo ( 'Thai<br>' );

echo "<input type = submit name= submit2>";
echo ( '<input type = reset value="Clear Form" >' );

echo ( '</form>' );

}

pg_close($dbcon);
?>

</body>
</html>

coopster

12:19 am on Mar 2, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Try less than or equal to:
for($j=0; $j<=$nrows; $j++)

Also, (PHP 4 >= 4.2.0) you may want to consider using the PostgreSQL functions pg_num_rows and pg_query rather than pg_numrows and pg_exec. From the PHP manual:


pg_num_rows -- This function used to be called pg_numrows()

pg_query -- pg_exec() is still available for compatibility reasons but users are encouraged to use the newer name.

Just a heads up.