MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 25th, 2006, 05:56 AM
john128 john128 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 12 john128 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 8 m 45 sec
Reputation Power: 0
Previous Next Function Driving me Mad

Hi,

I have been trying to add the previous next function with page numbers a la google to the folowing code but I just cannot to it. Please could someone help me.

PHP Code:
include("/data.inc");
 
  
$connection mysql_connect($host,$user,$password)
       or die (
"couldn't connect to server");
  
$db mysql_select_db($database,$connection)
       or die (
"Couldn't select database");
     


 
$query "SELECT * FROM propertydetailstable ";
 if (
$_POST['type'] == 'no_pref' AND $_POST['interest'] == 'no_pref') {
    
$query .= "WHERE Beds >= \"{$_POST[minbeds]}\" AND Eurocal >= \"{$_POST['minprice']}\" AND Eurocal <= \"{$_POST['maxprice']}\" ORDER BY Eurocal";       }
    elseif  (
$_POST['type'] == 'no_pref') { 
 
$query .= "WHERE Location_Look_up=\"{$_POST['interest']}\" AND Beds >= \"{$_POST[minbeds]}\" AND Eurocal >= \"{$_POST['minprice']}\" AND Eurocal <= \"{$_POST['maxprice']}\" ORDER BY Eurocal";   
    }
    elseif (
$_POST['interest'] == 'no_pref') { */
    
$query .= "WHERE Dwelling=\"{$_POST['type']}\" AND Beds >= \"{$_POST[minbeds]}\" AND Eurocal >= \"{$_POST['minprice']}\" AND Eurocal <= \"{$_POST['maxprice']}\" ORDER BY Eurocal";   
  }
    else {
            
$query .= "WHERE Location_Look_up=\"{$_POST['interest']}\" AND Dwelling=\"{$_POST['type']}\" AND Beds >= \"{$_POST[minbeds]}\" AND Eurocal >= \"{$_POST['minprice']}\" AND Eurocal <= \"{$_POST['maxprice']}\" ORDER BY Eurocal"
            }
  
$result mysql_query($query)
       or die (
"Couldn't execute query.");

  while (
$row mysql_fetch_array($result,MYSQL_ASSOC))   
  { 

echo 
'<br><br><A title="View details" ';
echo 
'href="/propertydetails.php?ref=';
echo 
"{$row['Ref_No']}";
echo 
'">View ';
echo 
'details</A> <br><br></div>';
echo 
'<div class="clear2"></div>';
 }


?> 


Thanks John

Reply With Quote
  #2  
Old August 28th, 2006, 09:55 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
What does this code produce?
An error? An incorrect URL?

What does the rendered HTML look like?
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter!
DevArticles Forum Moderator

"The net is a waste of time, and that's exactly what's right about it." -- William Gibson

Reply With Quote
  #3  
Old August 28th, 2006, 01:15 PM
john128 john128 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 12 john128 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 8 m 45 sec
Reputation Power: 0
The code in the PHP brakets is the code I used and like it is it works fine, but I need it to display the search results useing the criteria from the search form.

I tried adding the code below which searches the database for the results using an if statement but i just do not know how to add it to the code below.

Do i need to create a temporary table with the search results?


if ($_POST['type'] == 'no_pref' AND $_POST['interest'] == 'no_pref') {
$sql .= "WHERE Beds >= \"{$_POST[minbeds]}\" AND Eurocal >= \"{$_POST['minprice']}\" AND Eurocal <= \"{$_POST['maxprice']}\" ORDER BY Eurocal"; }
elseif ($_POST['type'] == 'no_pref') {
$sql .= "WHERE Location_Look_up=\"{$_POST['interest']}\" AND Beds >= \"{$_POST[minbeds]}\" AND Eurocal >= \"{$_POST['minprice']}\" AND Eurocal <= \"{$_POST['maxprice']}\" ORDER BY Eurocal";
}
elseif ($_POST['interest'] == 'no_pref') {
/*$query .= "WHERE Dwelling=\"".$_POST['type']."\" AND Beds >= \"".$_POST[minbeds]."\" AND Eurocal >= \"".$_POST['minprice']."\" AND Eurocal <= \"".$_POST['maxprice']."\"";
} */
$sql .= "WHERE Dwelling=\"{$_POST['type']}\" AND Beds >= \"{$_POST[minbeds]}\" AND Eurocal >= \"{$_POST['minprice']}\" AND Eurocal <= \"{$_POST['maxprice']}\" ORDER BY Eurocal";
}
else {
$sql .= "WHERE Location_Look_up=\"{$_POST['interest']}\" AND Dwelling=\"{$_POST['type']}\" AND Beds >= \"{$_POST[minbeds]}\" AND Eurocal >= \"{$_POST['minprice']}\" AND Eurocal <= \"{$_POST['maxprice']}\" ORDER BY Eurocal";
}





PHP Code:
<?php
  
include("access.inc");
   
$connection mysql_connect($host,$user,$password)
       or die (
"couldn't connect to server");
  
$db mysql_select_db($database,$connection)
       or die (
"Couldn't select database");
         



class 
MySQLPagedResults {

   var 
$total_results_sql;
   var 
$current_page;
   var 
$results_per_page;
   var 
$links_per_page;
   var 
$previous_link_text;
   var 
$next_link_text;

   function 
MySQLPagedResults($total_results_sql,$page_name,$u  rl_string,$results_per_page,$links_per_page,$first  _link_text,$previous_link_text,$next_link_text,$la  st_link_text,$seperator) {
      
$this->total_results_sql $total_results_sql;
      if(!isset(
$_GET[$page_name])) {
         
$this->current_page 1;
      } else {
         
$this->current_page $_GET[$page_name];
      }
      
$this->results_per_page $results_per_page;
      
$this->links_per_page $links_per_page;
      
$this->previous_link_text $previous_link_text;
      
$this->next_link_text $next_link_text;
      
$this->first_link_text $first_link_text;
      
$this->last_link_text $last_link_text;
      
$this->page_name $page_name;
      
$this->url_string $url_string;
      
$this->seperator $seperator;
   }

   function 
totalResults() {
      
$query mysql_query($this->total_results_sql);
      
$result mysql_fetch_array($query);
      return 
$result[0];
   }

   function 
totalPages() {
      return 
ceil($this->totalResults()/$this->results_per_page);
   }

   function 
currentOffset() {
      return (
$this->current_page-1)*$this->results_per_page;
   }

   function 
isFirstPage() {
      return (
$this->current_page <= 1);
   }

   function 
isLastPage() {
      return (
$this->current_page >= $this->totalPages());
   }

   function 
getPrevNav() {
      
$nav='';
      
//Deal with previous link
      
if(!$this->isFirstPage()) {
         
$nav.='<a href="?'.$this->page_name.'='.($this->current_page-1).''.$this->url_string.'">'.$this->previous_link_text.'</a>';
      } else {
         
$nav.=$this->previous_link_text;
      }
      return 
$nav;
   }

   function 
getNextNav() {
      
//Deal with next link
      
if(!$this->isLastPage()) {
         
$nav.='<a href="?'.$this->page_name.'='.($this->current_page+1).''.$this->url_string.'">'.$this->next_link_text.'</a>';
      } else {
         
$nav.=$this->next_link_text;
      }
      return 
$nav;
   }

   function 
getFirstNav() {
      
$nav='';
      
//Deal with previous link
      
if(!$this->isFirstPage()) {
         
$nav.='<a href="?'.$this->page_name.'=1'.$this->url_string.'">'.$this->first_link_text.'</a>';
      } else {
         
$nav.=$this->first_link_text;
      }
      return 
$nav;
   }

   function 
getLastNav() {
      
$nav='';
      
//Deal with previous link
      
if(!$this->isLastPage()) {
         
$nav.='<a href="?'.$this->page_name.'='.$this->totalPages().''.$this->url_string.'">'.$this->last_link_text.'</a>';
      } else {
         
$nav.=$this->last_link_text;
      }
      return 
$nav;
   }

   function 
getResultNumbersStart() {
      return (
$this->current_page*$this->results_per_page)-$this->results_per_page+1;
   }

   function 
getResultNumbersEnd() {
      return 
$this->getResultNumbersStart()+$this->results_per_page-1;
   }

   function 
getStartNumber() {
      
$links_per_page_half $this->links_per_page/2;
      if(
$this->current_page<=$links_per_page_half) {
         return 
1;
      } elseif(
$this->current_page>=$this->totalPages()-$links_per_page_half) {
         return 
$this->totalPages()-$this->links_per_page+1;
      } else {
         return 
$this->current_page-$links_per_page_half;
      }
   }

   function 
getEndNumber() {
      if(
$this->totalPages() < $this->links_per_page) {
         return 
$this->totalPages();
      } else {
         return 
$this->links_per_page;
      }
   }

   function 
getPagesNav() {
      
$nav='';
      for(
$i=$this->getStartNumber(); $i<$this->getStartNumber()+$this->getEndNumber(); $i++) {
         if(
$i!=$this->current_page) {
            
$nav.="<a href='?".$this->page_name."=$i".$this->url_string."'>$i</a>";
         } else {
            
$nav.="$i";
         }
         if(
$i!=$this->getStartNumber()+$this->getEndNumber()-1) { $nav.=$this->seperator; }
      }
      return 
$nav;
   }

}







$paging_results = new MySQLPagedResults("SELECT count(*) FROM propertydetailstable","page","",25,10,"<<","Previous","Next",">>"," | ");



//Make the variables from the class easier to read/use
$first_nav $paging_results->getFirstNav();
$prev_nav $paging_results->getPrevNav();
$next_nav $paging_results->getNextNav();
$last_nav $paging_results->getLastNav();
$pages_nav $paging_results->getPagesNav();
$offset $paging_results->currentOffset();
$results_per_page $paging_results->results_per_page;
$current_page $paging_results->current_page;
$total_pages $paging_results->totalPages();
$start_number $paging_results->getResultNumbersStart();
$end_number $paging_results->getResultNumbersEnd();

//Loop through a table of our database using the $offset and $results_per_page variables from our class.
$sql "SELECT * FROM propertydetailstable LIMIT $offset,$results_per_page";

$query mysql_query($sql);
while(
$row mysql_fetch_array($query)) {
 
#  echo $data[0] . ", ";
   
echo '<div class="summary">';
echo 
'<div class="resultsTitle"><span class="propertyResultsListingHeader">';
echo 
"{$row['Ref No']}";
echo 
' in ';
echo 
"{$row['Location_Look_up']}";
}

echo 
"<p><b>Page:</b> $current_page of $total_pages &nbsp;|&nbsp; <b>Results:</b> $start_number - $end_number<br>";
echo 
"$first_nav $prev_nav $pages_nav $next_nav $last_nav</p>";


?>

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Previous Next Function Driving me Mad


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 2 hosted by Hostway