This is the results page2 I use to output data collected from page1 (a form page). (this code I got originally from a post here)
I modified it to work on my site. If I don't include the $_POST variable it works great on displaying all records. But I want to allow users to POST from a form their criteria.
Below is code that works great if I don't use the $_POST variable, my problem is a user will use a form to POST the information to this page2, The first page shows me the first record correctly, and tells me how many records. example Page 1 of 133,, but when I try to navigate to the next page I get this error:
Notice: Trying to get property of non-object in C:\Program Files\Apache Group\Apache2\htdocs\www\website\searchallhousetype.php on line 93
and so on for all the other objects....
I'm thinking that that I'm doing something wrong with the $_POST.
Here is the code listed below:
<?
include("dbviewplansinfo.inc.php");
mysql_connect("localhost",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
// change the database information as needed or
// use your own connection method
// database connection variables
// next two functions are to set up our navigation
function previousPage() {
global $prev;
if ($prev == 0) {
echo " ";
}
else {
echo "<a href=\"$_SERVER[PHP_SELF]?page=$prev\">Previous</a>";
}
}
function nextPage() {
global $next;
global $num_rows;
if ($next <= $num_rows) {
echo "<a href=\"$_SERVER[PHP_SELF]?page=$next\">Next</a>";
}
else {
echo " ";
}
}
// The following statement sets the various variables
// used to navigate our database
if (isset($GET['page'])) {
$page = $GET['page'];
$prev = $page - 1;
$current = $page;
$next = $page + 1;
$limit = $prev;
}
else {
$prev = 0;
$current = 1;
$next = 2;
$limit = $prev;
}
// We need to see just how many entries there are in the table
// don't forget to change index_test to your own table
$num_rows = mysql_result(mysql_query("SELECT COUNT(*) FROM houseplans Where housetype = '".$_POST['housetype']."'"),0);
// Now we fetch the information from the db, using the LIMIT
// function of the sql statement to only fetch the single row we want.
// What the $limit variable is set to above is where the pointer
// will start in the table, this is called the offset. The next
// number limits the number of rows returned, in this case we only
// want one.
$query = "SELECT plan, housetype, sqft, bedrooms, garage, bathrooms, houseimage, sqftarea FROM houseplans Where housetype = '".$_POST['housetype']."' LIMIT $limit, 1";
$result = mysql_query($query);
// I like to turn the information into objects for handling
$row = mysql_fetch_object($result);
// Now we output the information in a meaningful way,
// note the use of the previousPage and nextPage functions
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Hodder Construction Ltd. - View Plans</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
</HEAD>
<BODY BACKGROUND="images/contactinpic.gif">
<table width="90%" align="center" cellpadding="3" cellspacing="3" border="1">
<tr>
<td colspan="6" align="center"><a href="index2.html"><IMG SRC="images/home.gif"></a><a href="AboutUs.html"><IMG SRC="images/ourcompany.jpg"></a><a href="sales.html"><IMG SRC="images/sales.jpg"></a><a href="Renovations.html"><IMG SRC="images/renovations.jpg"></a><a href="ClientsResidential.html"><IMG SRC="images/clients.jpg"></a><a href="ContactInfo.html"><IMG SRC="images/contactus.jpg"></a></td>
</tr>
<tr>
<td align="center"><B>Plan</B></td>
<td align="center"><B>House Type</B></td>
<td align="center"><B>Square Feet</B></td>
<td align="center"><B>Bedrooms</B></td>
<td align="center"><B>Bathrooms</B></td>
<td align="center"><B>Garages</B></td>
</tr>
<tr>
<td align="center"><? echo stripslashes($row->plan); ?></td>
<td align="center"><? echo stripslashes($row->housetype); ?></td>
<td align="center"><? echo stripslashes($row->sqft); ?></td>
<td align="center"><? echo stripslashes($row->bedrooms); ?></td>
<td align="center"><? echo stripslashes($row->bathrooms); ?></td>
<td align="center"><? echo stripslashes($row->garage); ?></td>
</tr>
<tr>
<td align="center"><? previousPage(); ?> </td>
<td colspan="4" align="center"><? echo $current. " of " .$num_rows; ?></td>
<td align="center"> <? nextPage(); ?></td>
</tr>
<tr>
<td colspan="6" align="center"><IMG SRC="plansimages/<? echo stripslashes($row->houseimage); ?>"></TD>
<tr>
<td align="center"><? previousPage(); ?> </td>
<td colspan="4" align="center"><? echo $current. " of " .$num_rows; ?></td>
<td align="center"> <? nextPage(); ?></td>
</tr>
<tr>
<td align="center"><IMG SRC="images/logosmall.gif"></td>
<td colspan="4" align="center">For pricing, or more information<br>on this plan, please click on the below link<br><A HREF="mailto:info@hodder.ca?subject=More info on Plan <? echo stripslashes($row->plan); ?>">info@hodder.ca</A></td>
<td align="center"><IMG SRC="images/logosmall.gif"></td>
</tr>
<tr>
<td colspan="6" align="center"><a href="index2.html"><IMG SRC="images/home.gif"></a><a href="AboutUs.html"><IMG SRC="images/ourcompany.jpg"></a><a href="sales.html"><IMG SRC="images/sales.jpg"></a><a href="Renovations.html"><IMG SRC="images/renovations.jpg"></a><a href="ClientsResidential.html"><IMG SRC="images/clients.jpg"></a><a href="ContactInfo.html"><IMG SRC="images/contactus.jpg"></a></td>
</tr>
</table>
</BODY>
</HTML>
<?
// close the database connection
mysql_close();
?>
Any help on steering me in the right direction would be greatly appreciated.