472,139 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,139 software developers and data experts.

Php Paging not showing all records

I have a problem that I've spent countless hours on and I'm more than certain this is a obviuos issue to an expert but I am still learning. I have a paging script that I have modified to display a certian amount of records per page. But when I click on the next link , no new result are displayed it keep displaying the same result. Here is a sample of the script
<?php include('hdb.html'); ?>
// Get the search variable from URL
$var = @$_GET['category'] ;
$trimmed = trim($var); //trim whitespace from the stored variable

// rows to return

// check for an empty string and display a message.
if ($trimmed == "")
echo "<p class=T1>Please enter a search...</p>";

// check for a search parameter
if (!isset($var))
echo "<p class=T1>We dont seem to have a search parameter!</p>";

//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("xxxxx","xxxxxxx","xxxxxx"); //(host, username, password)

//specify database ** EDIT REQUIRED HERE **
mysql_select_db("xxxxxxxxx") or die("Unable to select database"); //select which database we're using

// Build SQL Query
$query = "select * from pix where category like \"%$trimmed%\"
order by category, pid, albumname, "; // EDIT HERE and specify your table and field names for the SQL query


// If we have no results, offer a google search as an alternative

if ($numrows == 0)
echo "<h4>Results</h4>";
echo "<p class=T1>Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results</p>";

// google
echo "<p class=T1><a href=\"http://www.google.com/search?q="
. $trimmed . "\" target=\"_blank\" title=\"Look up
" . $trimmed . " on Google\">Click here</a> to try the
search on google</p>";

// next determine if s has been passed to script, if not use 0
if (empty($s)) {

// get results
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");

// display what the person searched for
echo '<center><table width="550" border="0" cellspacing="1" cellpadding="2" bgcolor="#Ffffff"><tr>';
echo '<td width=230 class=T1>';
echo "<p class=T1>Your searched for: &quot;" .$var . "&quot;</p>";
echo '</td>
<td align=right width=335 padding="3" bgcolor=#eoeccc class=T1>
//html goes here

// begin to show results set
echo "";
$count = 1 + $s ;

// now you can display the results returned
while ($row= mysql_fetch_array($result)) {
$state = stripslashes($row["state"]);
$pid= stripslashes($row['pid']);
$albumname= stripslashes($row['albumname']);

echo '<center><table width="550" border="0" cellspacing="1" cellpadding="2" bgcolor="#F7F7F7"><tr>
<td onmouseover="this.className=\'bgcl\';" onmouseout="this.className=\'gb2\';" width=330 align=top bgcolor=#Ffffff class=T1>
//html from output goes here
echo "</table></center>";
$count++ ;

$currPage = (($s/$limit) + 1);

//break before paging
echo "<br />";

// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
print "&nbsp;<a href=\"".$_SERVER['PHP_SELF']."??s=$prevs&category=$var\">&lt;&lt;
Prev 10</a>&nbsp&nbsp;";

// calculate number of pages needing links

// $pages now contains int of pages needed unless there is a remainder from division

if ($numrows%$limit) {
// has remainder so add one page

// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

// not last page so give NEXT link

echo "&nbsp;<a href=\"".$_SERVER['PHP_SELF']."?s=$news&category=$var\">Next 10 &gt;&gt;</a>";

$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "<center><p class=T1>Showing results $b to $a of $numrows</p></center>";

<?php include('footer.html'); ?>
I've already modified the php self function to work properly but the info being pass back to page when next link is clicked is not envoking the script to display the next set of records
May 8 '07 #1
7 2775
code green
1,726 Expert 1GB
You are conducting this test, [PHP]if (empty($s)) {
$s=0;[/PHP]but have not read the value of $s through your GET array so $s will always be zero. You seem to pass it OK [PHP]echo "&nbsp;<a href=\"".$_SERVER['PHP_SELF']."
?s=$news&category=$var\">Next 10 &gt;&gt;</a>";[/PHP] but only read category [PHP]$var = @$_GET['category'] ;[/PHP]By the way DO NOT USE '@' except when deploying the final script live. This is a terrible habit.
May 8 '07 #2
I think I grasp what your saying. I will try it again and post back my findings latter.
May 8 '07 #3
5,821 Expert 4TB
By the way DO NOT USE '@' except when deploying the final script live. This is a terrible habit.
I might add to that by saying that you should really never need to use '@' ever. If you want to hide your errors from the end User, just set:

Expand|Select|Wrap|Line Numbers
  1. display_errors = Off
  2. log_errors = On
And optionally:

Expand|Select|Wrap|Line Numbers
  1. error_log /path/to/error_log
in your php.ini file (usually located at /usr/local/lib/php.ini or somewhere else on Windows [somebody who uses a 'doze box on a regular basis will probably be a lot more helpful than I can in that respect]).

Not only will your User never see error messages, but you don't have to go back into your code and remove a bunch of '@' characters if your script messes up.

[EDIT: And most web hosting providers allow you to edit a php.ini file at the root level of your site.]
May 8 '07 #4
Hi ,I just got in and used your advice the script worked perfectly. I added the Variable s to the get function! No more paging problem

Thanks for the help
May 9 '07 #5
code green
1,726 Expert 1GB
Well done Underground. I agree with pbmods. Why do people feel compelled to use '@'. in their scripts, especially when developing? I use the following code within a config file on all my scripts. Then I can use DEBUG and print 'Any message I want' all over the script and simply set DEBUG to zero to turn everything off.[PHP]

error_reporting(E_ALL | E_STRICT);
May 10 '07 #6
Hey hey hey hey hey hey
Jul 2 '07 #7
5,821 Expert 4TB
Heya, Mesut.

Hey hey hey hey hey hey
Jul 2 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Jignesh Desai | last post: by
2 posts views Thread by asad | last post: by
2 posts views Thread by Jignesh Desai | last post: by
3 posts views Thread by kartic | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.