Current location: Hot Scripts Forums » Programming Languages » PHP » Please Help! Display Records page by page


Please Help! Display Records page by page

Closed Thread
  #1 (permalink)  
Old 07-05-04, 03:13 AM
peter_toronto peter_toronto is offline
New Member
 
Join Date: Jul 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question Please Help! Display Records page by page

Hello:

I have a problem. I want to display 1000 records in page by page with 25 records in each page. and page number at the bottom as page link. Now I am displaying all records in one page with following codes.

I appreciate your help.

Thank you,
regards,

Peter from toronto

PHP Code:

<?php
include '../config.php';

$db mysql_connect("$host_db","$user_db","$passwd_db");
mysql_select_db ($database_name,$db);

$qtable "users";
$qfields "username, purchases";
$qcondition "where uid='$current_uid' and purchases!= 0";
$qresult mysql_query("select $qfields from $qtable $qcondition");

$i=mysql_num_rows($qresult);


list( 
$username)=mysql_fetch_row($qresult);

$username=stripslashes($username);

if(
$i ) { die("<img src=no-entry.jpg align='center'> <font size=2 color=red><b>Sorry, you have no access to this section.<br> Please contact the system administrator.<b></font>"); }//done


$qtable "customers";
$qfields "cid, company, name, phone, machines";
    
$qcondition "where uid='$current_uid' ";

//$qcondition = "where sconfirm='0'";

if(! isset($cid)) { 
    
$qresult mysql_query("select $qfields from $qtable $qcondition order by cid DESC limit 25");
} else {
    
$qresult mysql_query("select $qfields from $qtable $qcondition order by cid DESC limit 25");
}

$i=mysql_num_rows($qresult);
$grandtotal=0;

if(
$i 0) {
    while(list(
$cid,$company,$name$phone$machines)=mysql_fetch_row($qresult)){
                
//$cid=stripslashes($cid);
                
$uid=stripslashes($uid);
                
$company=stripslashes($company);
                
$name=stripslashes($name);
                
$phone=stripslashes($phone);
                
$machines=stripslashes($machines);
?>
                    <tr> 
                      <td align="center" valign="top"> <div align="center"> <font size="1" face="Verdana, Arial, Helvetica, sans-serif"><A href="view.php?cid=<? echo $cid?>"><? echo $cid?></A> 
                          </font></div></td>
                      <td align="left" valign="top"> <font size="-3" face="Verdana, Arial, Helvetica, sans-serif"><A href="view.php?cid=<? echo $cid?>"><? echo $company?></A> 
                        </font></div></td>
                      <td align="left" valign="top"><div align="left"></div>
                        <font size="1" face="Verdana, Arial, Helvetica, sans-serif"><? echo $name?></font></td>
                      <td align="left" valign="top"><div align="left"></div>
                        <font size="1" face="Verdana, Arial, Helvetica, sans-serif"><? echo $phone?></font></td>
                      <td align="left" valign="top"> <div align="left"> <font size="1" face="Verdana, Arial, Helvetica, sans-serif"><? echo $machines?> 
                          </font></div></td>
                    </tr>
                    <? } } ?>

Last edited by Nico; 02-20-08 at 09:13 AM.
  #2 (permalink)  
Old 07-05-04, 07:25 AM
rsuresh rsuresh is offline
Newbie Coder
 
Join Date: May 2004
Location: India
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Hi ..

Ive not altered your code just go through this snippet that i have used may be this will defenitely help you a lot
PHP Code:

<?php


//Create a connection to yourserver.
//Print error message to user if connection to server has failed.
$connection mysql_connect("localhost""root","pass")or die ("Unable to connect to SERVER");

//database name
$db="db_name";
$database = @mysql_select_db($db,$connection)or die ("could not select  database ");
// database connection stuff here
$rows_per_page 10;
$sql "SELECT * FROM tbl";
$result mysql_query($sql$connection);
//calculating the total number of rows present in the table;
$total_records mysql_num_rows($result);
//finding out how many pages that will be printed.
$pages ceil($total_records $rows_per_page);
//echo "$total_records";
// Free result
mysql_free_result($result);





/**NEXT SECTION**/
if (!isset($screen))
$screen 0;

$page_count=$screen+1;
$total_pages=$pages-1;

//echo "Now Showing <strong> [$page_count / $total_pages] </strong> ";
echo "<br />";

$start $screen $rows_per_page;
$sql "SELECT fieldname1, fieldname2 FROM tbl ";
$sql .= "LIMIT $start$rows_per_page";

$result mysql_query($sql,$connection);
$rows mysql_num_rows($result);
if(
$result)
{
    echo
"<table width=\"100%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing =\"0\" >"
        echo 
"<tr>";
            echo 
"<td> <strong> fieldname1  </strong></td> <td> <strong> fieldname2  </strong></td> ";
        echo 
"</tr>";
}        
        
while(
$row =mysql_fetch_array($result))
{
    
$Name $row["fieldname1"];
    
$Name2$row["fieldname1"];
    echo 
"<tr>";
            echo 
"<td> <strong>$Name </strong></td> <td> $Name2 </td> ";
    echo 
"</tr>";
}    
echo
"</table>";

echo 
"<p><hr></p>\n";
echo
"<center>";
// let's create the dynamic links now
if ($screen 0) {
 
  
$screen_back$screen-1;
  echo 
"<a href=\"yourfilename.php?screen=$screen_back\">Previous<img src=\"Prevgrey.gif\" border=\"0\" /> </a> &nbsp";
}
// page numbering links now
/*for ($i = 0; $i < $pages; $i++) {
  $url = "yourfilename.php?screen=" . $i;
  echo " | <a href=\"$url\">$i</a> | ";
}*/

if (($screen+1) < $pages)  {
     
  
$screen$screen+1;
  echo 
" &nbsp<a href=\"yourfilename.php?screen=$screen\"><img src=\"Nextgrey.gif\" border=\"0\"> Next</a>\n";
}
echo
"</center>";
echo 
"<p><hr></p>\n";

?>
Hope this will help you defenitely
Suresh

Last edited by Nico; 02-20-08 at 09:13 AM.
  #3 (permalink)  
Old 07-27-04, 02:00 PM
peter_toronto peter_toronto is offline
New Member
 
Join Date: Jul 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you Suresh for your help. It works perfectly.
I owe you a coffee.

peter from Toronto
  #4 (permalink)  
Old 02-20-08, 08:41 AM
arunet arunet is offline
New Member
 
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
http://www.phpjabbers.com/php--mysql-select-data-and-split-on-pages-php25.html this is an effective method
  #5 (permalink)  
Old 02-20-08, 08:48 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Would be easier to read your code if you put it in the PHP tags. Regardless, there are thousands of results for what you are trying to do on google

Jay
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
  #6 (permalink)  
Old 02-20-08, 09:12 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
This is 4 years old. I doubt the OP still needs help with this.


Closed.
Closed Thread

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
page browsing problem mivec PHP 3 04-17-04 03:43 AM
page load time display epic1231 PHP 2 03-10-04 11:33 PM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM
Create a next page link when there are too many records to be display in a webpage Han84 ASP 0 10-19-03 10:32 PM


All times are GMT -5. The time now is 05:08 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.