Jump to content

Recommended Posts

I'm trying to add pagination but failing badly :)

 

Here's my code:

$query = "SELECT COUNT(*) FROM searchacts";
$pages = new Paginator;  
$pages->items_total = $num_rows[0];  
$pages->mid_range = 9;  
$pages->paginate();  
echo $pages->display_pages();

  //### Initialize variables
  $pages = isset($_GET['page']) ? $_GET['page'] : FALSE ;
  $category = isset($_GET['categories']) ? $_GET['categories'] : FALSE ;
  $sort     = isset($_GET['sort']) ? $_GET['sort'] : FALSE ;
  $upto     = isset($_GET['upto']) ? $_GET['upto'] : FALSE ;


  //### Create the URL parameters
  $urlParameters = '?categories='. $category .'&upto='. $upto .'&sort='. $sort .'&page='. $pages .'';


  //### Start the query variable
  $query = 'SELECT * FROM `searchacts` $pages->limit';


  //### Initialize query options
  $queryOptions = array();


  //### Now check each of the sorting values
  //### Check which category we are searching in
  if($category == 'PopandRock') {
    $queryOptions[] = "`category` = 'Pop and Rock'";
  } else if($category == 'SoulFunkDiscoMowtown') {
    $queryOptions[] = "`category` = 'Soul, Funk, Disco and Motown'";
  }  
  //### Check what value upto we are returning
  if($upto == '100') {
    $queryOptions[] = "`price` <= 100";
  } else if($upto == '200') {
    $queryOptions[] = "`price` <= 200";
  } else if($upto == '300') {
    $queryOptions[] = "`price` <= 300";
  }  


  //### Create final query
  $queryWhere = isset($queryOptions[0]) ? ' WHERE '.implode(' AND ', $queryOptions) : '' ;


  $finalQuery = $query . $queryWhere;


  //### Add the order by to the end of the query
  if($sort == 'PriceLow') {
    $finalQuery .= ' ORDER BY `price` ASC';
  } else if($sort == 'PriceHigh') {
    $finalQuery .= ' ORDER BY `price` DESC';
  } 


  //echo $finalQuery;


  //echo '<br>'.$urlParameters;


$result = mysql_query($finalQuery);


$num = mysql_num_rows($result);

and i've been trying to use this script/tutorial: http://net.tutsplus.com/tutorials/php/how-to-paginate-data-with-php/

 

so i've included the paginator.class.php, the $pages->limit on my select and tried to implement it into my url parameters

 
Any Ideas?
 
Thanks
Link to comment
https://forums.phpfreaks.com/topic/275565-help-with-pagination/
Share on other sites

Try this, not sure if it will work 100% as I don't have your code infront of me. Report aback any errors.

 

 

  //### Initialize variables
  $pages    = isset($_GET['page']) ? $_GET['page'] : FALSE ;
  $category = isset($_GET['categories']) ? $_GET['categories'] : FALSE ;
  $sort     = isset($_GET['sort']) ? $_GET['sort'] : FALSE ;
  $upto     = isset($_GET['upto']) ? $_GET['upto'] : FALSE ;

  //### Create the URL parameters
  $urlParameters = '?categories='. $category .'&upto='. $upto .'&sort='. $sort .'&page='. $pages .'';

  //### Start the query variable
  $query = 'SELECT * FROM `searchacts`';

  //### Initialize query options
  $queryOptions = array();

  //### Now check each of the sorting values
  //### Check which category we are searching in
  if($category == 'PopandRock') {
    $queryOptions[] = "`category` = 'Pop and Rock'";
  } else if($category == 'SoulFunkDiscoMowtown') {
    $queryOptions[] = "`category` = 'Soul, Funk, Disco and Motown'";
  }
  //### Check what value upto we are returning
  if($upto == '100') {
    $queryOptions[] = "`price` <= 100";
  } else if($upto == '200') {
    $queryOptions[] = "`price` <= 200";
  } else if($upto == '300') {
    $queryOptions[] = "`price` <= 300";
  } 

  //### Create final query
  $queryWhere = isset($queryOptions[0]) ? ' WHERE '.implode(' AND ', $queryOptions) : '' ;

  //### Add the order by to the end of the query
  if($sort == 'PriceLow') {
    $finalQuery .= ' ORDER BY `price` ASC';
  } else if($sort == 'PriceHigh') {
    $finalQuery .= ' ORDER BY `price` DESC';
  }

  //### Pagination
  $query = "SELECT COUNT(*) FROM searchacts {$queryWhere}";
  $pages = new Paginator; 
  $pages->items_total = $num_rows[0]; 
  $pages->mid_range = 9; 
  $pages->paginate(); 
  echo $pages->display_pages();

  //### Create the final query
  $finalQuery = $query . $queryWhere . $pages->limit;

  $result = mysql_query($finalQuery);

  $num = mysql_num_rows($result);



 

Edit* - I'm sure you're removing code from your actual code, please post all code you have.

Edited by PaulRyan

Ok full code:

 <?php include 'paginator.class.php'; ?>
      
  <?php
error_reporting(E_ALL);
ini_set("display_errors", 1);


$username="username";
$password="password";
$database="database";


mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
  
  //### Initialize variables
  $pages = isset($_GET['page']) ? $_GET['page'] : FALSE ;
  $category = isset($_GET['cat']) ? $_GET['cat'] : FALSE ;
  $subcategory = isset($_GET['categories']) ? $_GET['categories'] : FALSE ;
  $sort     = isset($_GET['sort']) ? $_GET['sort'] : FALSE ;
  $upto     = isset($_GET['upto']) ? $_GET['upto'] : FALSE ;


  //### Create the URL parameters
  $urlParameters = '?cat'. $category .'&categories='. $subcategory .'&upto='. $upto .'&sort='. $sort .'&page='. $pages .'';


  //### Start the query variable
  $query = 'SELECT * FROM `searchacts`';


  //### Initialize query options
  $queryOptions = array();


 //### Now check each of the sorting values
  //### Check which category we are searching in
  if($category == 'Bands') {
    $queryOptions[] = "`category` = 'Bands'";
  } else if($category == 'Acoustic') {
    $queryOptions[] = "`category` = 'Acoustic'";
  } else if($category == 'DJ') {
    $queryOptions[] = "`category` = 'DJ'";
  } else if($category == 'AlternativeEntertainment') {
    $queryOptions[] = "`category` = 'AlternativeEntertainment'";
  }


  //### Now check each of the sorting values
  //### Check which subcategory we are searching in
  if($subcategory == 'PopandRock') {
    $queryOptions[] = "`subcategory` = 'Pop and Rock'";
  } else if($subcategory == 'SoulFunkDiscoMowtown') {
    $queryOptions[] = "`subcategory` = 'Soul, Funk, Disco and Motown'";
  } else if($subcategory == 'JazzBigBandSwingBlues') {
    $queryOptions[] = "`subcategory` = 'Jazz, Big Band, Swing and Blues'";
  } else if($subcategory == 'Tribute') {
    $queryOptions[] = "`subcategory` = 'Tribute'";
  } else if($subcategory == 'Cuban') {
    $queryOptions[] = "`subcategory` = 'Cuban'";
  } else if($subcategory == 'Mexican') {
    $queryOptions[] = "`subcategory` = 'Mexican'";
  } else if($subcategory == 'Medieval') {
    $queryOptions[] = "`subcategory` = 'Medieval'";
  } else if($subcategory == 'Strings') {
    $queryOptions[] = "`subcategory` = 'Strings'";
  } else if($subcategory == 'Woodwind') {
    $queryOptions[] = "`subcategory` = 'Woodwind'";
  } else if($subcategory == 'Harpist') {
    $queryOptions[] = "`subcategory` = 'Harpist'";
  } else if($subcategory == 'Piano/GuitarVocalDuo') {
    $queryOptions[] = "`subcategory` = 'Piano/GuitarVocalDuo'";
  } else if($subcategory == 'SoloPiano') {
    $queryOptions[] = "`subcategory` = 'Solo Piano'";
  } else if($subcategory == 'PianoandVocal') {
    $queryOptions[] = "`subcategory` = 'Piano and Vocal'";
  } else if($subcategory == 'FireArtists') {
    $queryOptions[] = "`subcategory` = 'FireArtists'";
  } else if($subcategory == 'Magicians') {
    $queryOptions[] = "`subcategory` = 'Magicians'";
  } else if($subcategory == 'Caricaturists') {
    $queryOptions[] = "`subcategory` = 'Caricaturists'";
  } else if($subcategory == 'Comedians') {
    $queryOptions[] = "`subcategory` = 'Comedians'";
  } else if($subcategory == 'Acrobats') {
    $queryOptions[] = "`subcategory` = 'Acrobats'";
  }



  //### Check what value upto we are returning
  if($upto == '100') {
    $queryOptions[] = "`price` <= 100";
  } else if($upto == '200') {
    $queryOptions[] = "`price` <= 200";
  } else if($upto == '300') {
    $queryOptions[] = "`price` <= 300";
  } else if($upto == '400') {
    $queryOptions[] = "`price` <= 400";
  } else if($upto == '500') {
    $queryOptions[] = "`price` <= 500";
  } else if($upto == '600') {
    $queryOptions[] = "`price` <= 600";
  } else if($upto == '700') {
    $queryOptions[] = "`price` <= 700";
  } else if($upto == '800') {
    $queryOptions[] = "`price` <= 800";
  } else if($upto == '900') {
    $queryOptions[] = "`price` <= 900";
  } else if($upto == '1000') {
    $queryOptions[] = "`price` <= 1000";
  } else if($upto == '1500') {
    $queryOptions[] = "`price` <= 1500";
  } else if($upto == '2000') {
    $queryOptions[] = "`price` <= 2000";
  } else if($upto == '2500') {
    $queryOptions[] = "`price` <= 2500";
  } else if($upto == '3000') {
    $queryOptions[] = "`price` <= 3000";
  } else if($upto == '3500') {
    $queryOptions[] = "`price` <= 3500";
  } else if($upto == '4000') {
    $queryOptions[] = "`price` <= 4000";
  } else if($upto == '4500') {
    $queryOptions[] = "`price` <= 4500";
  } else if($upto == '5000') {
    $queryOptions[] = "`price` <= 5000";
  } else if($upto == '5500') {
    $queryOptions[] = "`price` <= 5500";
  } else if($upto == '6000') {
    $queryOptions[] = "`price` <= 6000";
  }
  

  //### Create final query
  $queryWhere = isset($queryOptions[0]) ? ' WHERE '.implode(' AND ', $queryOptions) : '' ;


  $finalQuery = $query . $queryWhere;


  //### Add the order by to the end of the query
  if($sort == 'PriceLow') {
    $finalQuery .= ' ORDER BY `price` ASC';
  } else if($sort == 'PriceHigh') {
    $finalQuery .= ' ORDER BY `price` DESC';
  } else if($sort == 'NameAZ') {
    $finalQuery .= ' ORDER BY `name` ASC';
  } else if($sort == 'NameZA') {
    $finalQuery .= ' ORDER BY `name` DESC';
  }


  //### Pagination
  $query = "SELECT COUNT(*) FROM searchacts {$queryWhere}";
  $pages = new Paginator; 
  $pages->items_total = $num_rows[0]; 
  $pages->mid_range = 9; 
  $pages->paginate(); 
  echo $pages->display_pages();


  //echo $finalQuery;


  //echo '<br>'.$urlParameters;


//### Create the final query
  $finalQuery = $query . $queryWhere . $pages->limit;


  $result = mysql_query($finalQuery);


  $num = mysql_num_rows($result);


?>
  
      <li><a href="<?PHP echo '?categories= &upto='. $upto .'&sort='. $sort .'';?>">All Acts</a></li>
      
       <li><a href="<?PHP echo '?cat=Bands&upto='. $upto .'&sort='. $sort .'';?>">Bands</a></li>
       
      <li><a href="<?PHP echo '?categories=PopandRock&upto='. $upto .'&sort='. $sort .'';?>">Pop and Rock</a></li>
      <li><a href=<?PHP echo '?categories=SoulFunkDiscoMowtown&upto='. $upto .'&sort='. $sort .'';?>>Soul, Funk, Disco and Motown</a></li>
      <li><a href="<?PHP echo '?categories=JazzBigBandSwingBlues&upto='. $upto .'&sort='. $sort .'';?>">Jazz, Big Band, Swing and Blues</a></li>
      <li><a href=<?PHP echo '?categories=Tribute&upto='. $upto .'&sort='. $sort .'';?>>Tribute</a></li>
      <li><a href=<?PHP echo '?categories=Cuban&upto='. $upto .'&sort='. $sort .'';?>>Cuban</a></li>
      <li><a href="<?PHP echo '?categories=Mexican&upto='. $upto .'&sort='. $sort .'';?>">Mexican</a></li>
      <li><a href=<?PHP echo '?categories=Medieval&upto='. $upto .'&sort='. $sort .'';?>>Medieval</a></li>
      
      <li><a href="<?PHP echo '?cat=Acoustic&upto='. $upto .'&sort='. $sort .'';?>">Acoustic</a></li>
      
      <li><a href=<?PHP echo '?categories=Strings&upto='. $upto .'&sort='. $sort .'';?>>Strings</a></li>
      <li><a href=<?PHP echo '?categories=Woodwind&upto='. $upto .'&sort='. $sort .'';?>>Woodwind</a></li>
      <li><a href=<?PHP echo '?categories=Harpist&upto='. $upto .'&sort='. $sort .'';?>>Harpist</a></li>
      <li><a href=<?PHP echo '?categories=Piano/GuitarVocalDuo&upto='. $upto .'&sort='. $sort .'';?>>Piano / Guitar Vocal Duo</a></li>
      <li><a href=<?PHP echo '?categories=SoloPiano&upto='. $upto .'&sort='. $sort .'';?>>Solo Piano</a></li>
      <li><a href="<?PHP echo '?categories=PianoandVocal&upto='. $upto .'&sort='. $sort .'';?>">Piano and Vocal</a></li>
      
      <li><a href="<?PHP echo '?cat=DJ&upto='. $upto .'&sort='. $sort .'';?>">DJ</a></li>
      
      <li><a href="<?PHP echo '?cat=AlternativeEntertainment&upto='. $upto .'&sort='. $sort .'';?>">Alternative Entertainment</a></li>
      
      <li><a href=<?PHP echo '?categories=FireArtists&upto='. $upto .'&sort='. $sort .'';?>>Fire Artists</a></li>
      <li><a href=<?PHP echo '?categories=Magicians&upto='. $upto .'&sort='. $sort .'';?>>Magicians</a></li>
      <li><a href=<?PHP echo '?categories=Caricaturists&upto='. $upto .'&sort='. $sort .'';?>>Caricaturists</a></li>
      <li><a href=<?PHP echo '?categories=Comedians&upto='. $upto .'&sort='. $sort .'';?>>Comedians</a></li>
      <li><a href="<?PHP echo '?categories=Acrobats&upto='. $upto .'&sort='. $sort .'';?>">Acrobats</a></li>


  <div id="sortingcontainer"> <span class="sortbyheader">Sort By:</span>
<form action='?' method='get' name='form_filter' class="sortoptions" >  
<input type="hidden" name="upto" value="<?PHP echo $upto;?>">
<input type="hidden" name="categories" value="<?PHP echo $subcategory;?>">
  <select name="sort" >  
      <option value="all">All</option>  
      <option value="PriceLow">Price (Low to High)</option>  
      <option value="PriceHigh">Price (High to Low)</option> 
      <option value="NameAZ">Name (A-Z)</option>  
      <option value="NameZA">Name (Z-A)</option>  


      </select>  
      
  
    <br />  
    <input type='submit' value = 'Re-Order your results'>  
</form>
  </div>
  <div id="sortingcontainer"> <span class="sortbyheader">Sort By:</span>
  
<form action='?' method='get' name='form_filter' class="sortoptions" >  
 <input type="hidden" name="sort" value="<?PHP echo $sort;?>">
 <input type="hidden" name="categories" value="<?PHP echo $subcategory;?>">
  <select name="upto">  
      <option value="100">Up to £100</option>  
      <option value="200">Up to £200</option>  
      <option value="300">Up to £300</option>
      <option value="400">Up to £400</option>  
      <option value="500">Up to £500</option>  
      <option value="600">Up to £600</option>  
      <option value="700">Up to £700</option>  
      <option value="800">Up to £800</option>  
      <option value="900">Up to £900</option>  
      <option value="1000">Up to £1000</option> 
      <option value="1500">Up to £1500</option>  
      <option value="2000">Up to £2000</option>  
      <option value="2500">Up to £2500</option>  
      <option value="3000">Up to £3000</option>  
      <option value="3500">Up to £3500</option> 
      <option value="4000">Up to £4000</option>  
      <option value="4500">Up to £4500</option>  
      <option value="5000">Up to £5000</option>  
      <option value="5500">Up to £5500</option>  
      <option value="6000">Up to £6000</option>  
</select>  
    <br />  
    <input type='submit' value = 'Re-Order your results'>  
</form>
  </div>
  <?php
$i=0;
while ($i < $num) {


$image=mysql_result($result,$i,"image");
$name=mysql_result($result,$i,"name");
$subcategory=mysql_result($result,$i,"subcategory");
$description=mysql_result($result,$i,"description");
$stamps=mysql_result($result,$i,"stamps");
$stickmen=mysql_result($result,$i,"stickmen");
$price=mysql_result($result,$i,"price");
$view=mysql_result($result,$i,"view");
$actpagelink=mysql_result($result,$i,"actpagelink");


?>
  
  
  <a href="<?php echo $actpagelink; ?>" class="searchitem">
  <div class="searchimage"><img src="<?php echo $image; ?>"/></div>
  <div class="searchtext">
    <div class="searchname"><?php echo $name; ?></div>
    <div class="searchcategory"><?php echo $subcategory; ?></div>
    <div class="searchdescription"><?php echo $description; ?></div>
  </div>
  <div class="searchstamps"><img src="<?php echo $stamps; ?>" /></div>
  <div class="searchstickmen"><img src="<?php echo $stickmen; ?>" /></div>
  <div class="searchprice"><span class="pricefrom">from</span>£<?php echo $price; ?></div>
    
  <div class="searchview"><img src="<?php echo $view; ?>" /></div>
    
    
  </a>
  
  <?php
$i++;
}




mysql_close();
?>

and where i'm testing it: http://tinyurl.com/ct8w7js

 

Its all updated on the server so its as it is above

 

Thanks

Ok  I've given up with that script, just cant get it to work. So got this other script which i've got half working:

 

$tableName="searchacts"; 
$targetpage = "searchtestingv4.php";  
$limit = 5; 

$query = "SELECT COUNT(*) as num FROM $tableName";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];

$stages = 3;
$page = mysql_escape_string($_GET['page']);
if($page){
$start = ($page - 1) * $limit; 
}else{
$start = 0; 
} 

    // Get page data
$query = "SELECT * FROM $tableName LIMIT $start, $limit";
$result = mysql_query($query);


// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1; 
$next = $page + 1; 
$lastpage = ceil($total_pages/$limit); 
$LastPagem1 = $lastpage - 1; 


$paginate = '';
if($lastpage > 1)
{ 








$paginate .= "<div class='paginate'>";
// Previous
if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
}else{
$paginate.= "<span class='disabled'>previous</span>"; }






// Pages 
if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up
{ 
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} 
}
}
elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few?
{
// Beginning only hide later pages
if($page < 1 + ($stages * 2)) 
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} 
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>"; 
}
// Middle hide some front and some back
elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} 
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>"; 
}
// End only hide early pages
else
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} 
}
}
}


// Next
if ($page < $counter - 1){ 
$paginate.= "<a href='$targetpage?page=$next'>next</a>";
}else{
$paginate.= "<span class='disabled'>next</span>";
}


$paginate.= "</div>"; 




}
 echo $total_pages.' Results';
 // pagination
 echo $paginate;






//### Initialize variables
  $category = isset($_GET['cat']) ? $_GET['cat'] : FALSE ;
  $subcategory = isset($_GET['categories']) ? $_GET['categories'] : FALSE ;
  $sort     = isset($_GET['sort']) ? $_GET['sort'] : FALSE ;
  $upto     = isset($_GET['upto']) ? $_GET['upto'] : FALSE ;


  //### Create the URL parameters
  $urlParameters = '?cat'. $category .'&categories='. $subcategory .'&upto='. $upto .'&sort='. $sort .'';


  //### Start the query variable
  $query = 'SELECT * FROM `searchacts`';


  //### Initialize query options
  $queryOptions = array();




 //### Now check each of the sorting values
  //### Check which subcategory we are searching in
  if($category == 'Bands') {
    $queryOptions[] = "`category` = 'Bands'";
  } else if($category == 'Acoustic') {
    $queryOptions[] = "`category` = 'Acoustic'";
  } else if($category == 'DJ') {
    $queryOptions[] = "`category` = 'DJ'";
  } else if($category == 'AlternativeEntertainment') {
    $queryOptions[] = "`category` = 'AlternativeEntertainment'";
  }






  //### Now check each of the sorting values
  //### Check which subcategory we are searching in
  if($subcategory == 'PopandRock') {
    $queryOptions[] = "`subcategory` = 'Pop and Rock'";
  } else if($subcategory == 'SoulFunkDiscoMowtown') {
    $queryOptions[] = "`subcategory` = 'Soul, Funk, Disco and Motown'";
  } else if($subcategory == 'JazzBigBandSwingBlues') {
    $queryOptions[] = "`subcategory` = 'Jazz, Big Band, Swing and Blues'";
  } else if($subcategory == 'Tribute') {
    $queryOptions[] = "`subcategory` = 'Tribute'";
  } else if($subcategory == 'Cuban') {
    $queryOptions[] = "`subcategory` = 'Cuban'";
  } else if($subcategory == 'Mexican') {
    $queryOptions[] = "`subcategory` = 'Mexican'";
  } else if($subcategory == 'Medieval') {
    $queryOptions[] = "`subcategory` = 'Medieval'";
  } else if($subcategory == 'Strings') {
    $queryOptions[] = "`subcategory` = 'Strings'";
  } else if($subcategory == 'Woodwind') {
    $queryOptions[] = "`subcategory` = 'Woodwind'";
  } else if($subcategory == 'Harpist') {
    $queryOptions[] = "`subcategory` = 'Harpist'";
  } else if($subcategory == 'Piano/GuitarVocalDuo') {
    $queryOptions[] = "`subcategory` = 'Piano / Guitar Vocal Duo'";
  } else if($subcategory == 'SoloPiano') {
    $queryOptions[] = "`subcategory` = 'Solo Piano'";
  } else if($subcategory == 'PianoandVocal') {
    $queryOptions[] = "`subcategory` = 'Piano and Vocal'";
  } else if($subcategory == 'FireArtists') {
    $queryOptions[] = "`subcategory` = 'FireArtists'";
  } else if($subcategory == 'Magicians') {
    $queryOptions[] = "`subcategory` = 'Magicians'";
  } else if($subcategory == 'Caricaturists') {
    $queryOptions[] = "`subcategory` = 'Caricaturists'";
  } else if($subcategory == 'Comedians') {
    $queryOptions[] = "`subcategory` = 'Comedians'";
  } else if($subcategory == 'Acrobats') {
    $queryOptions[] = "`subcategory` = 'Acrobats'";
  }




  //### Check what value upto we are returning
  if($upto == '100') {
    $queryOptions[] = "`price` <= 100";
  } else if($upto == '200') {
    $queryOptions[] = "`price` <= 200";
  } else if($upto == '300') {
    $queryOptions[] = "`price` <= 300";
  } else if($upto == '400') {
    $queryOptions[] = "`price` <= 400";
  } else if($upto == '500') {
    $queryOptions[] = "`price` <= 500";
  } else if($upto == '600') {
    $queryOptions[] = "`price` <= 600";
  } else if($upto == '700') {
    $queryOptions[] = "`price` <= 700";
  } else if($upto == '800') {
    $queryOptions[] = "`price` <= 800";
  } else if($upto == '900') {
    $queryOptions[] = "`price` <= 900";
  } else if($upto == '1000') {
    $queryOptions[] = "`price` <= 1000";
  } else if($upto == '1500') {
    $queryOptions[] = "`price` <= 1500";
  } else if($upto == '2000') {
    $queryOptions[] = "`price` <= 2000";
  } else if($upto == '2500') {
    $queryOptions[] = "`price` <= 2500";
  } else if($upto == '3000') {
    $queryOptions[] = "`price` <= 3000";
  } 
  


  //### Create final query
  $queryWhere = isset($queryOptions[0]) ? ' WHERE '.implode(' AND ', $queryOptions) : '' ;


  $finalQuery = $query . $queryWhere;


  //### Add the order by to the end of the query
  if($sort == 'PriceLow') {
    $finalQuery .= ' ORDER BY `price` ASC';
  } else if($sort == 'PriceHigh') {
    $finalQuery .= ' ORDER BY `price` DESC';
  } else if($sort == 'NameAZ') {
    $finalQuery .= ' ORDER BY `name` ASC';
  } else if($sort == 'NameZA') {
    $finalQuery .= ' ORDER BY `name` DESC';
  }




  //echo $finalQuery;


  //echo '<br>'.$urlParameters;


$result = mysql_query($finalQuery);


$num = mysql_num_rows($result);


?>

But... it only works if I remove this from the original code:  

 

//### Start the query variable

  $query = 'SELECT * FROM `searchacts`';
 
but then the filters/sorting functions stop working.
 
I would have thought the data select on the pagination would work with the filters aswell:
 
 // Get page data
$query = "SELECT * FROM $tableName LIMIT $start, $limit";
 
as its basically the same except from the start limit
 
 
Thanks
Edited by dan292
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.