Webmasterpals  

Go Back   Webmasterpals > Site Management > Website Programming

Reply
 
Thread Tools Display Modes
  #1  
Old 02-18-2008, 10:37 PM
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Feb 2008
Location: hrwebdir.org
Posts: 309
Blog Entries: 11
admin has a reputation beyond reputeadmin has a reputation beyond reputeadmin has a reputation beyond reputeadmin has a reputation beyond reputeadmin has a reputation beyond reputeadmin has a reputation beyond reputeadmin has a reputation beyond reputeadmin has a reputation beyond reputeadmin has a reputation beyond reputeadmin has a reputation beyond reputeadmin has a reputation beyond repute
Default how to create paging with php/mysql?

how to create paging with php and mysql database. i have a list of articles pulled from database and i want to show in pages of 10? how to do it?

need some help here...
Reply With Quote
  #2  
Old 02-19-2008, 09:24 AM
pbu's Avatar
pbu pbu is offline
Administrator
 
Join Date: Feb 2008
Location: hrwebdir.org
Posts: 1,077
pbu has a reputation beyond reputepbu has a reputation beyond reputepbu has a reputation beyond reputepbu has a reputation beyond reputepbu has a reputation beyond reputepbu has a reputation beyond reputepbu has a reputation beyond reputepbu has a reputation beyond reputepbu has a reputation beyond reputepbu has a reputation beyond reputepbu has a reputation beyond repute
Default Re: how to create paging with php/mysql?

It is not that hard to create paging with mysql/mysql

Here is the logic:

Imagine you have 50 results and you want to break down into 5 pages with 10 results each. So the script should receive a GET variable like page=5 in order to display results. Also the mysql query should be limited pagewise with LIMIT START,OFFSET

i am posting the script here. Note that it is a home made script and may not work exactly. i am posting this to illustrate the simple logic behind posting.


Quote:
// Find the total listings
$rs_total_listings = mysql_query("select *
from listings
where approved = 1

", $link)
or die("Couldn't execute query".mysql_error());
// Paging & Alphabetical properties//

$limit = 15; //pages limit

if (!isset($_GET['page']) )
{ $start=0;
$show_paging = "limit $start,$limit";
} else
{
$start = ($_GET['page'] - 1) * $limit;
$show_paging = "limit $start,$limit"; }

$total_listings = mysql_num_rows($rs_total_listings);
$total_pages = ceil($total_listings/$limit);

$rs_listings = mysql_query("select `title`,`desc`,`url`
from listings
where did = '$did' and approved = 1
$show_alphabetical
order by paid desc, added desc
$show_paging

", $link)
or die("Couldn't execute query".mysql_error());



// outputting the pages
if ($total_listings > $limit)
{
echo "<h4>Pages: ";
$i = 0;
while ($i < $total_pages)
{
$page_no = $i+1;
echo "<a href=\"$page_no\">$page_no</a> ";
$i++;
}
echo "</h4>";
}
If i remember correctly there are also good php classes available to generate different varieties of paging with mysql results.
EZPaging: http://www.best-php-scripts.com/details460.htm
Reply With Quote
  #3  
Old 02-21-2008, 05:44 AM
Deviatore's Avatar
Deviatore Deviatore is offline
Member
 
Join Date: Feb 2008
Posts: 34
Deviatore is on a distinguished road
Default Re: how to create paging with php/mysql?

hey pbu it seems like you know good PHP...
can u help me too? I want to build a search engine for my site...i mean not like google, just to search inside my site
Reply With Quote
  #4  
Old 05-03-2008, 04:42 AM
SunDrop SunDrop is offline
Member
 
Join Date: May 2008
Posts: 34
SunDrop is on a distinguished road
Default Re: how to create paging with php/mysql?

Quote:
Originally Posted by Deviatore View Post
hey pbu it seems like you know good PHP...
can u help me too? I want to build a search engine for my site...i mean not like google, just to search inside my site
You could actually use the Google applications to do this. It would put a Google search box on your site and then give the visitors the ability to choose whether they would like to search the "web" for their words or to search your site instead.
Reply With Quote
Reply


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 12:30 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Webmasterpals.com (c) 2008 - All Rights Reserved