473,563 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Php Paging not showing all records

41 New Member
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]
<?php include('hdb.ht ml'); ?>
<?php
// Get the search variable from URL
$var = @$_GET['category'] ;
$trimmed = trim($var); //trim whitespace from the stored variable

// rows to return
$limit=2;

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

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

//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

$numresults=mys ql_query($query );
$numrows=mysql_ num_rows($numre sults);

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

if ($numrows == 0)
{
echo "<h4>Result s</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)) {
$s=0;
}

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

// display what the person searched for
echo '<center><tabl e width="550" border="0" cellspacing="1" cellpadding="2" bgcolor="#Fffff f"><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
</td>
</tr></table></center>';

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

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

echo '<center><tabl e width="550" border="0" cellspacing="1" cellpadding="2" bgcolor="#F7F7F 7"><tr>
<td onmouseover="th is.className=\' bgcl\';" onmouseout="thi s.className=\'g b2\';" width=330 align=top bgcolor=#Ffffff class=T1>
//html from output goes here
</td>
</tr>';
}
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
$prevs=($s-$limit);
print "&nbsp;<a href=\"".$_SERV ER['PHP_SELF']."??s=$prevs&ca tegory=$var\">& lt;&lt;
Prev 10</a>&nbsp&nbsp;" ;
}

// calculate number of pages needing links
$pages=intval($ numrows/$limit);

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

if ($numrows%$limi t) {
// has remainder so add one page
$pages++;
}

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

// not last page so give NEXT link
$news=$s+$limit ;

echo "&nbsp;<a href=\"".$_SERV ER['PHP_SELF']."?s=$news&cate gory=$var\">Nex t 10 &gt;&gt;</a>";
}

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

?>
<?php include('footer .html'); ?>
[/PHP]
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 2937
code green
1,726 Recognized Expert Top Contributor
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=\"".$_SERV ER['PHP_SELF']."
?s=$news&catego ry=$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
underground
41 New Member
I think I grasp what your saying. I will try it again and post back my findings latter.
;-)
May 8 '07 #3
pbmods
5,821 Recognized Expert Expert
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
  3.  
And optionally:

Expand|Select|Wrap|Line Numbers
  1. error_log /path/to/error_log
  2.  
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
underground
41 New Member
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 Recognized Expert Top Contributor
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]
if(!defined('DE BUG'))
define('DEBUG', 1);

if(DEBUG)
error_reporting (E_ALL | E_STRICT);
else
ini_set('displa y_errors',0);[/PHP]
May 10 '07 #6
Mesut
3 New Member
Hey hey hey hey hey hey
Jul 2 '07 #7
pbmods
5,821 Recognized Expert Expert
Heya, Mesut.

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

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

Similar topics

2
3520
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned from my search and how many records I have set it to display per page. All great so far, HOWEVER..... When you click the next link to see the...
1
1248
by: Jignesh Desai | last post by:
Most of you must have worked on paging feature of DataGrid. its works fine as long as you have more no of records to show, but if you have configured 20 records per page and no of records you retrieved is less then 20 then also pager gets rendered at the bottom of the grid showing "1". most of us do not bother about it , but Clients...
2
2212
by: asad | last post by:
Hello friends, i am designing a ASP.NET page where i want to use custom paging bcoz data is too heavy so pls tell me how can i use custom paging in ASP.NET Thanks
4
6258
by: karunakar rao | last post by:
Hi All I need some help. I have been populated 50,000 Records in asp.net C# datagrid. Ever page has 10 records Example "<< Prev 1 2 3 4 5 6 7 8 9 10 Next>> Iam showing like that in my datagrid When ever click the Next Buttuon Iam getting data from database Total(50,000) Records.Every time performanse wise it is taken lot of
2
1380
by: Jignesh Desai | last post by:
Info:: Most of you must have worked on paging feature of DataGrid. its works fine as long as you have more no of records to show, but if you have configured 20 records per page and no of records you retrieved is less then 20 then also pager gets rendered at the bottom of the grid showing "1". most of us do not bother about it , but Clients...
8
2791
by: rbg | last post by:
I did use query plans to find out more. ( Please see the thread BELOW) I have a question on this, if someone can help me with that it will be great. In my SQL query that selects data from table, I have a where clause which states : where PermitID like @WorkType order by WorkStart DESC
3
3733
by: Ronald S. Cook | last post by:
I was told that if calling lots of records from the database (let's say 100,000), that the GridView's paging feature would automatically "handle" everything. But the 100,000 records are still coming to the client, right? I mean, the paging feature isn't somehow making calls to the database for 25 records at a time or anything like that...
3
1498
by: kartic | last post by:
hi all, i am very new in Ajax programming, my problem is, i am creating paging with Ajax functionality, and with Ajax i am calling javascript in each page no, my javascript function make the ajax request to the server. now i am showing 10 records per page and in my DB there is 14 total records, and i have 2 pages total. in my first page 10...
4
9763
Fary4u
by: Fary4u | last post by:
Hi i've done the Datagrid view but only problem with displaying pages here is the code for Datagrid <% Dim I, iPageSize iPageSize = 9 'Change pages Dim arrPhotoNames
0
7579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7943
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5479
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5204
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2077
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.