General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 10th, 2002, 01:57 AM
Mr Chocloate Mr Chocloate is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Anglesea
Posts: 12 Mr Chocloate User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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($test00); 

// 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>&nbsp; "
for (
$i 0$i $pageCount$i++) { 
   echo 
"<a href=\"{$HTTP_SERVER_VARS['PHP_SELF']}?page=$i\">[$i]</a>&nbsp; "

echo 
"<a href=\"{$HTTP_SERVER_VARS['PHP_SELF']}?page=".($pageCount 1)."\">[ last ]</a>&nbsp; "

if (!isset(
$HTTP_GET_VARS['page']) || $HTTP_GET_VARS['page'] < || $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($query1MYSQL_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.

Reply With Quote
  #2  
Old September 10th, 2002, 03:43 PM
adunsulag adunsulag is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 5 adunsulag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 32 sec
Reputation Power: 0
Send a message via AIM to adunsulag
Give the part that is giving you the error

Could you please just give us a small section of where the error is?

Reply With Quote
  #3  
Old September 10th, 2002, 07:03 PM
Mr Chocloate Mr Chocloate is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Anglesea
Posts: 12 Mr Chocloate User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
line 54:
PHP Code:
 $total mysql_result($test00); 


And the sql query you can see the errors here

http://www.sunet.com.au/~adcell/tes...0&submit=Search


it just keeps repeating. thanks adunsulag for taking a look.


Reply With Quote
  #4  
Old September 10th, 2002, 07:06 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
$query .= $from .= $where .= " LIMIT $start, $perpage";

that should be

$query = $query . $from . $where . " LIMIT $start, $perpage";

Reply With Quote
  #5  
Old September 10th, 2002, 07:54 PM
Mr Chocloate Mr Chocloate is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Anglesea
Posts: 12 Mr Chocloate User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank's Ben your a PHP machine! & Flash

one more question if you will? do you know why i lose my query string?my sever is using php 4.0.6 ? do you know another way to do PHP_SELF? whithout all this $HTTP_SERVER_VARS?

PHP Code:
echo "<a href=\"{$HTTP_SERVER_VARS['PHP_SELF']}?page=0\">[ first ]</a>&nbsp; "
for (
$i 0$i $pageCount$i++) { 
   echo 
"<a href=\"{$HTTP_SERVER_VARS['PHP_SELF']}?page=$i\">[$i]</a>&nbsp; "

echo 
"<a href=\"{$HTTP_SERVER_VARS['PHP_SELF']}?page=".($pageCount 1)."\">[ last ]</a>&nbsp; "

if (!isset(
$HTTP_GET_VARS['page']) || $HTTP_GET_VARS['page'] < || $HTTP_GET_VARS['page'] > $pageCount) { 
   
$start 0

else { 
   
$start $perpage $HTTP_GET_VARS['page']; 


Reply With Quote
  #6  
Old September 10th, 2002, 09:24 PM
adunsulag adunsulag is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 5 adunsulag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 32 sec
Reputation Power: 0
Send a message via AIM to adunsulag
$PHP_SELF;

why not just use $PHP_SELF?

Reply With Quote
  #7  
Old September 10th, 2002, 10:37 PM
Mr Chocloate Mr Chocloate is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Anglesea
Posts: 12 Mr Chocloate User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks for your help guys everything works great now.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > whats wrong with this code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway