Jump to content

Recommended Posts

Does anyone know why this doesn't work?

 

I get the first 2 results shown and if i press next or last i just get blank pages with the prev first etc buttons. It recognizes there are 9 pages which i can navigate but they are all blank.

 

Thanks in advance.

 

//Paging system.

 

if (isset($_GET['pageno'])) {

  $pageno = $_GET['pageno'];

} else {

  $pageno = 1;

}

 

$query2 = "SELECT count(*) FROM image_bank";

$result2 = mysql_query($query2) or trigger_error("SQL", E_USER_ERROR);

$query_data = mysql_fetch_row($result2);

$numrows = $query_data[0];

 

$rows_per_page = 2;

$lastpage      = ceil($numrows/$rows_per_page);

 

$pageno = (int)$pageno;

if ($pageno > $lastpage) {

  $pageno = $lastpage;

}

if ($pageno < 1) {

  $pageno = 1;

}

 

$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;

 

$query = "SELECT DISTINCT * FROM image_bank WHERE $wordx $typex $flavorx $tiersx $servesx $pricex $limit" ;

 

$result = mysql_query($query) ;

 

//$rowamnt = mysql_num_rows($result) ; //Count how many results there are.

 

if ($numrows > 0) //If there are more than 0 results...

{

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

{

 

$dbtitle = $row['title'] ;

$dbdescr = $row['description'] ;

$dbtags = $row['tags'] ;

$dbdec = $row['decorator'] ;

$dbtiers = $row['tiers'] ;

$dbtype = $row['type'] ;

$dbflavor = $row['flavor'] ;

$dbserves = $row['serves'] ;

$dbprice = $row['price'] ;

$imgurl = $row['url'];

$thumburl = $row['thumb_url'] ;

$rating = $row['rating'] ;

 

echo "$dbtags" . "<br />" ;

echo "$dbtitle" . "<br />" ;

echo "Decorated by : $dbdec" . "<br />" ;

echo "Description : $dbdescr" . "<br />" ;

echo "$dbtiers tier cake" . "<br />" ;

echo "Type : $dbtype cake" . "<br />" ;

echo "Flavor : $dbflavor" . "<br />" ;

echo "Serves : $dbserves" . "<br />" ;

echo "Costs : $dbprice" . "<br />" ;

echo 'Information Page : <a href="' . "$imgurl" . '">' . "$imgurl" . "</a>" . "<br />" ;

echo '<img src="' . "$thumburl" . '" height="100" width="50" />' ;

echo "$rating" ;

 

}

if ($pageno == 1) {

  echo " FIRST PREV ";

} else {

  echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";

  $prevpage = $pageno-1;

  echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";

}

if ($pageno == $lastpage) {

  echo " NEXT LAST ";

} else {

  $nextpage = $pageno+1;

  echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";

  echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";

}

echo " ( Page $pageno of $lastpage ) ";

}

Link to comment
https://forums.phpfreaks.com/topic/149924-pagination-help-blank-next-pages/
Share on other sites

Hi, just above what i just posted:

 

if(isset($word))

{

include ('eliminator.php') ; //Include the word cleaner, deletes symbols etc.

include ('stemmer.php') ; //Include the Stemmer Algorythm, "tests" = "test" etc.

 

$stemmer = new PorterStemmer ; //Call class in the stemmer.php file.

$stemmed_string = $stemmer->stem(strtolower($word)); //force words to lower case.

 

$cleanup = new Cleaner ; //Call word cleaner class in the eliminator.php file.

$stemmed_string = $cleanup->parseString($stemmed_string) ;

 

$sanction = split(" ",$stemmed_string) ; //Spaces constiture a new word?

 

foreach ($sanction as $array => $V)

{

$x_string .= ''.$V.' ' ;

}

$x_string = substr($x_string,0,(strlen($x_string)-1)) ;

 

$split_stemmed = split(" ",$x_string) ;

 

while(list($key,$V)=each($split_stemmed))

{

if($V<>" " AND strlen($V) > 0){

$wordx .=  "(tags LIKE '%$V%' OR title LIKE '%$V%' OR Description LIKE '%$V%' OR decorator LIKE '%$V%') OR" ;

}

}

$wordx = substr($wordx,0,(strlen($wordx)-3)) ;

 

}

 

if(isset($type))

{

if(isset($word))

{

$typex = "&& type LIKE '%$type%'" ;

}

else

$typex = "type LIKE '%$type%'" ;

}

 

if(isset($flavor))

{

if(isset($word) || isset($type))

{

$flavorx = "&& flavor LIKE '%$flavor%'" ;

}

else

$flavorx = "flavor LIKE '%$flavor%'" ;

}

 

if(isset($tiers))

{

if(isset($word) || isset($type) || isset($flavor))

{

$tiersx = "&& tiers LIKE '%$tiers%'" ;

}

else

$tiersx = "tiers LIKE '%$tiers%'" ;

}

 

if(isset($serves))

{

if(isset($word) || isset($type) || isset($flavor) || isset($tiers))

{

$servesx = "&& serves LIKE '%$serves%'" ;

}

else

$servesx = "serves LIKE '%$serves%'" ;

}

 

if(isset($price))

{

if(isset($word) || isset($type) || isset($flavor) || isset($tiers) || isset($serves))

{

$pricex = "&& price LIKE '%$price%'" ;

}

else

$pricex = "price LIKE '%$price%'" ;

}

 

Cheers.

I found a clue, i told it to echo the number of rows:

 

if ($numrows > 0) //If there are more than 0 results...

{

echo "<p>$numrows results found</p>" ;

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

{

 

ON the first page if i search for somthing in my base i get 18 as the number of rows returned, this is correct, but when i go to page to it only shows 2.

Any ideas?

 

I've also tried the following but no luck (highlighted in red):

 

<?PHP

 

session_start() ;

 

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Cake Photos Decorators Suppliers</title>

<meta name="keywords" content="" />

<meta name="description" content="" />

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

 

<link href="../cakes-css.css" rel="stylesheet" type="text/css" />

</head>

 

<body>

<div id="page">' ;

include "../includes/headnav.html" ;

echo '<div id="head"></div>

 

<div id="search">' ;

include "../includes/header-search.html" ;

echo '</div>

<div id="sidebar">' ;

include "../includes/sidenav.html" ;

echo'</div>

<div id="main">' ;

 

if (!file_exists("dbconnect.php"))

{

die("Database settings not found, administrator intervention required.") ;

}

else

{

require("dbconnect.php") ; //Must connect to the database.

}

 

$word = $_POST['word'];

$type = $_POST['type'] ;

$flavor = $_POST['flavor'] ;

$tiers = $_POST['tiers'] ;

$serves = $_POST['serves'] ;

$price = $_POST['price'] ; 

 

//THIS IS THE VARIABLE THAT HAS THE POUND AND $ SYMBOLS IN.

 

//Strip symbols and malicious attempts.

 

$word = strip_tags($word) ;

 

//HTML default outputs the symbols even though they are coded in the drop down boxes, the below converts them back into their codes so they match with the codes in the database.

$symbol[0] = '£' ;

$symbol[1] = '&#x24;' ;

 

$replace[0] = '£' ;

$replace[1] = '$' ;

 

$price = str_replace($replace,$symbol,$price) ;

 

$def = "Dont Specify" ; //Default value for drop down boxes

 

if(!isset($word) || $word == "Enter Search Term" || $word == "") //If the word field has nothing in or has default text then...

{

unset($word) ; //Force clear.

}

if($type == $def)

{

unset($type) ;

}

if($flavor == $def)

{

unset($flavor) ;

}

if($tiers == $def)

{

unset($tiers) ;

}

if($serves == $def)

{

unset($serves) ;

}

if($price == $def)

{

unset($price) ;

}

 

if(!isset($word) && !isset($type) && !isset($flavor) && !isset($tiers) && !isset($serves) && !isset($price)) //If nothing has been set...

{

echo '<h1>Cake Photos - Nothing Searched For</h1>

<p>You did not specify anything to search for.</p>

<p>Either enter a word into the word field, or make a selection from at least one drop down box.</p>' ; //Message.

echo '</div><div id="rightzone">' ;

//include 'random.php' ;

echo '</div>

<div id="footer">' ;

include "../includes/footer.html" ;

 

echo '</div>

</div>

 

</body>

</html>' ;

die ; include("dbdisconnect.php") ;//End script and disconnect from database.

}

 

if(isset($word))

{

include ('eliminator.php') ; //Include the word cleaner, deletes symbols etc.

include ('stemmer.php') ; //Include the Stemmer Algorythm, "tests" = "test" etc.

 

$stemmer = new PorterStemmer ; //Call class in the stemmer.php file.

$stemmed_string = $stemmer->stem(strtolower($word)); //force words to lower case.

 

$cleanup = new Cleaner ; //Call word cleaner class in the eliminator.php file.

$stemmed_string = $cleanup->parseString($stemmed_string) ;

 

$sanction = split(" ",$stemmed_string) ; //Spaces constiture a new word?

 

foreach ($sanction as $array => $V)

{

$x_string .= ''.$V.' ' ;

}

$x_string = substr($x_string,0,(strlen($x_string)-1)) ;

 

$split_stemmed = split(" ",$x_string) ;

 

while(list($key,$V)=each($split_stemmed))

{

if($V<>" " AND strlen($V) > 0){

$wordx .=  "(tags LIKE '%$V%' OR title LIKE '%$V%' OR Description LIKE '%$V%' OR decorator LIKE '%$V%') OR" ;

}

}

$wordx = substr($wordx,0,(strlen($wordx)-3)) ;

echo "<h2>You Searched for $word</h2>" ;

 

}

 

if(isset($type))

{

if(isset($word))

{

$typex = "&& type LIKE '%$type%'" ;

}

else

$typex = "type LIKE '%$type%'" ;

}

 

if(isset($flavor))

{

if(isset($word) || isset($type))

{

$flavorx = "&& flavor LIKE '%$flavor%'" ;

}

else

$flavorx = "flavor LIKE '%$flavor%'" ;

}

 

if(isset($tiers))

{

if(isset($word) || isset($type) || isset($flavor))

{

$tiersx = "&& tiers LIKE '%$tiers%'" ;

}

else

$tiersx = "tiers LIKE '%$tiers%'" ;

}

 

if(isset($serves))

{

if(isset($word) || isset($type) || isset($flavor) || isset($tiers))

{

$servesx = "&& serves LIKE '%$serves%'" ;

}

else

$servesx = "serves LIKE '%$serves%'" ;

}

 

if(isset($price))

{

if(isset($word) || isset($type) || isset($flavor) || isset($tiers) || isset($serves))

{

$pricex = "&& price LIKE '%$price%'" ;

}

else

$pricex = "price LIKE '%$price%'" ;

}

 

//Paging system.

 

$page = (!isset($_GET['page']))? 1 : $_GET['page'] ;

$prev = ($page - 1) ;

$next = ($page + 1) ;

 

$max_results = 5 ;

 

$from = (($page * $max_results) - $max_results) ;

 

$resamnt = mysql_query("SELECT image_id FROM image_bank") ;

 

$total_results = mysql_num_rows($resamnt) ;

 

$total_pages = ceil($total_results / $max_results) ;

 

$pagination = '' ;

 

if($page > 1)

{

$pagination .= '<a href="search.php?page='.$prev.'">Previous</a>' ;

}

 

for ($i = 1; $i <= $total_pages; $i++)

{

if(($page) == $i)

{

$pagination .= $i ;

}

else

{

$pagination .= '<a href="search.php?page='.$i.'">'.$i."</a>";

}

}

 

if($page < $total_pages)

{

$pagination .= '<a href="search.php?page='.$next.'">Next</a>' ;

}

 

echo "$pagination" ;

 

$query = "SELECT * FROM image_bank WHERE $wordx $typex $flavorx $tiersx $servesx $pricex LIMIT $from, $max_results " ;

 

$result = mysql_query($query) ;

 

//$rowamnt = mysql_num_rows($result) ; //Count how many results there are.

 

if ($total_results > 0) //If there are more than 0 results...

{

if($total_results == 1)

{

$s = "" ;

}

else

{

$s = "s" ;

}

echo "<p>Which yielded <strong>$total_results</strong> result" . "$s</p>" ;

while($row = mysql_fetch_array($result))

{

 

$dbtitle = $row['title'] ;

$dbdescr = $row['description'] ;

$dbtags = $row['tags'] ;

$dbdec = $row['decorator'] ;

$dbtiers = $row['tiers'] ;

$dbtype = $row['type'] ;

$dbflavor = $row['flavor'] ;

$dbserves = $row['serves'] ;

$dbprice = $row['price'] ;

$imgurl = $row['url'];

$thumburl = $row['thumb_url'] ;

$rating = $row['rating'] ;

 

echo "$dbtags" . "<br />" ;

echo "$dbtitle" . "<br />" ;

echo "Decorated by : $dbdec" . "<br />" ;

echo "Description : $dbdescr" . "<br />" ;

echo "$dbtiers tier cake" . "<br />" ;

echo "Type : $dbtype cake" . "<br />" ;

echo "Flavor : $dbflavor" . "<br />" ;

echo "Serves : $dbserves" . "<br />" ;

echo "Costs : $dbprice" . "<br />" ;

echo 'Information Page : <a href="' . "$imgurl" . '">' . "$imgurl" . "</a>" . "<br />" ;

echo '<img src="' . "$thumburl" . '" height="100" width="50" />' ;

echo "$rating" ;

 

}

}

else

{

 

echo '<h1>Cake Photos - Nothing Found</h1>

<p>No cakes were found that match what you searched for.</p>

<p>Make sure your have entered a keyword OR have selected an item from atleast one drop down menu.</p>' ;

}

 

echo '</div><div id="rightzone">' ;

//include 'random.php' ;

echo '</div>

<div id="footer">' ;

include "../includes/footer.html" ;

 

echo '</div>

</div>

 

</body>

</html>' ;

 

include("dbdisconnect.php") ;

 

?>

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.