
September 10th, 2002, 01:57 AM
|
|
Junior Member
|
|
Join Date: Aug 2002
Location: Anglesea
Posts: 12
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
whats wrong with this code
I'm very tired can you help me. All i want to do is page the results of my query. Do you know how to do this? can you please fix my code?  my brain is fried. If you have a better way of doing this please show me
PHP Code:
<?php
// entries per page
$perpage = 5;
$totalquery = "SELECT COUNT(*)";
$query = "SELECT DISTINCT Image1, Suburb, Caption, Description, Properties.ID, Price, SuburbID";
$from = " FROM Properties, Suburbs";
$where = " WHERE Properties.ID > 0 AND Hide='N' AND Sold='N' AND SuburbID=Suburbs.ID ";
if ($buildid != "") { // An Suburb is selected
$where .= " AND BuildingID=$buildid";
}
if ($suburbid != "") { // An Suburb is selected
$where .= " AND SuburbID=$suburbid";
}
if ($agencyid != "") { // An Agency is selected
$where .= " AND PropertyAgencyID=$agencyid";
}
if ($cid != "") { // A category is selected
$from .= ", PropertyLookup";
$where .= " AND Properties.ID=PID AND CID=$cid";
}
if ($eid != "") { // A extra is selected
$from .= ", PropertyExtras";
$where .= " AND Properties.ID=PID AND EID=$eid";
}
if ($min != "") { // Some search text was specified
$where .= " AND Bedrooms >= '$min'";
}
if ($to != "") { // Some search text was specified
$where .= " AND Bedrooms < '$to'";
}
if ($pricefrom != "") { // Some search text was specified
$where .= " AND Price >= '$pricefrom'";
}
if ($priceto != "") { // Some search text was specified
$where .= " AND Price < '$priceto'";
}
$totalquery .= $from .= $where;
// get total entries in the db
$test = mysql_query($totalquery);
$total = mysql_result($test, 0, 0);
// calculate the number of pages
$pageCount = ceil($total / $perpage);
// display pages - now with first and last page
echo "<a href=\"{$HTTP_SERVER_VARS['PHP_SELF']}?page=0\">[ first ]</a> ";
for ($i = 0; $i < $pageCount; $i++) {
echo "<a href=\"{$HTTP_SERVER_VARS['PHP_SELF']}?page=$i\">[$i]</a> ";
}
echo "<a href=\"{$HTTP_SERVER_VARS['PHP_SELF']}?page=".($pageCount - 1)."\">[ last ]</a> ";
if (!isset($HTTP_GET_VARS['page']) || $HTTP_GET_VARS['page'] < 0 || $HTTP_GET_VARS['page'] > $pageCount) {
$start = 0;
}
else {
$start = $perpage * $HTTP_GET_VARS['page'];
}
$query .= $from .= $where .= " LIMIT $start, $perpage";
// for testing: i get a line error here line
echo "Totalquery = $totalquery <br>";
echo "Normalquery = $query <br>";
$query1 = mysql_query($query);
// some testing output
echo '<pre>';
while ($data = mysql_fetch_array($query1, MYSQL_ASSOC)) {
print_r($data);
}
echo '</pre>';
?>
you can see the result of this code here
http://www.sunet.com.au/~adcell/tes...0&submit=Search
Last edited by Mr Chocloate : September 10th, 2002 at 01:59 AM.
|