Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2008-02-16, 04:42 AM
Junior Member
 
Join Date: Feb 2008
Posts: 1
Impact Design is on a distinguished road
Post Help with Pagination

I am new to php scripting and I would greatly appreciate some help with pagination. So far here is the core of my script. Can someone help me paginate this page?

Code:
 
<?php
include("admin/includes/config.inc.php");
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY year DESC, month DESC, day DESC";
$result=mysql_query($sql);
$num_rows = mysql_num_rows($result);
?>
<style type="text/css">
<!--
.smbold {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 11px; }
.smmainit {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: normal;
font-size: 11px;
font-style: italic;
}
.smmain {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: normal;
font-size: 11px;
}
.link {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 11px; }
-->
</style>
<table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td width="105" align="center"><span class="smbold">Date</span></td>
<td width="264" align="center"><span class="smbold">Title</span></td>
<td width="81" align="center"><span class="smbold">mp3</span></td>
<td width="81" align="center" class="smbold"><div align="center">Download</div></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td valign="top"><div align="center" class="smmain">
<? echo $rows['month']; ?>/<? echo $rows['day']; ?>/<? echo $rows['year']; ?></span></td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="smbold"><? echo $rows['title']; ?></span></span></td>
</tr>
<tr>
<td class="smmainit"><? echo $rows['scripture']; ?></span></td>
</tr>
<tr>
<td class="smmainit"><? echo $rows['ser_series']; ?></td>
</tr>
<tr>
<td class="smmain"><? echo $rows['speaker']; ?></td>
</tr>
</table></td>
<td align="center" valign="top"><a href="mp3/<? echo $rows['file']; ?>" class="link">Listen</a></td>
<td align="center" valign="top"><div align="center"><a href="download.php?<? echo $rows['file']; ?>" class="link">Download</a></div></td>
</tr>
<?php
}
?>
</table>
<?php
mysql_close();
?>

Last edited by Impact Design; 2008-02-16 at 01:21 PM.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2008-02-18, 08:44 AM
Junior Member
 
Join Date: Feb 2008
Posts: 5
prafulkr is on a distinguished road
Default Pagination

<?php
include("admin/includes/config.inc.php");
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

/****************************/

if (isset($_GET['page']))
{
$page = $_GET['page'];
}
else
{
$page=1;
}
$start_from = ($page-1) * 10;

/****************************/

$sql="SELECT * FROM $tbl_name
ORDER BY year DESC, month DESC, day DESC
LIMIT $start_from, 10 "; //add this for feching limited record

$result=mysql_query($sql);
$num_rows = mysql_num_rows($result);

/****************************/


$row = mysql_fetch_row($result);
$num = mysql_num_rows($result);
$total_records = $row[0];
$total_pages = ceil($total_records / 10);

/****************************/
?>
<style type="text/css">
<!--
.smbold {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 11px; }
.smmainit {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: normal;
font-size: 11px;
font-style: italic;
}
.smmain {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: normal;
font-size: 11px;
}
.link {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 11px; }
-->
</style>
<table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td width="105" align="center"><span class="smbold">Date</span></td>
<td width="264" align="center"><span class="smbold">Title</span></td>
<td width="81" align="center"><span class="smbold">mp3</span></td>
<td width="81" align="center" class="smbold"><div align="center">Download</div></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td valign="top"><div align="center" class="smmain">
<? echo $rows['month']; ?>/<? echo $rows['day']; ?>/<? echo $rows['year']; ?></span></td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="smbold"><? echo $rows['title']; ?></span></span></td>
</tr>
<tr>
<td class="smmainit"><? echo $rows['scripture']; ?></span></td>
</tr>
<tr>
<td class="smmainit"><? echo $rows['ser_series']; ?></td>
</tr>
<tr>
<td class="smmain"><? echo $rows['speaker']; ?></td>
</tr>
</table></td>
<td align="center" valign="top"><a href="mp3/<? echo $rows['file']; ?>" class="link">Listen</a></td>
<td align="center" valign="top"><div align="center"><a href="download.php?<? echo $rows['file']; ?>" class="link">Download</a></div></td>
</tr>
<tr><td>

<?
echo "<font face='Verdana, Arial, Helvetica, sans-serif' color='#FF6633' size='1'><strong>Result Page:</strong></font>";
for ($i=1; $i<=$total_pages; $i++)
{
echo "<a href='pageName.php?page=$i&searchby=$scropt&keywor ds=$sctxt&selectcat=$selectcat'><font face='Verdana, Arial, Helvetica, sans-serif' color='#FF6633' size='1'> [<b>" . $i . "</b>]<font</a> ";
};
?>
</td></tr>
<?php
}
?>
</table>
<?php
mysql_close();
?>

try this..
I will split result in to multiple pages .
Reply With Quote
  #3 (permalink)  
Old 2008-02-18, 08:56 AM
Junior Member
 
Join Date: Feb 2008
Posts: 5
prafulkr is on a distinguished road
Default

if you want google like pagination
then use this code accordingly.


<?

//Previous and next page navigation.
$pageNum = $page - 1;
$Prev = " <a href=\"pageName.php?page=$pageNum&searchby=$scropt &keywords=$sctxt&selectcat=$selectcat\"><font face='Verdana, Arial, Helvetica, sans-serif' color='#FF6633' size='1'><strong> Previous&nbsp;&nbsp;</strong></font></a> ";
$pageNum = $page + 1;
$Next = " <a href=\"pageName.php?page=$pageNum&searchby=$scropt &keywords=$sctxt&selectcat=$selectcat\"><font face='Verdana, Arial, Helvetica, sans-serif' color='#FF6633' size='1'><strong>&nbsp;&nbsp;Next </strong></font></a> ";

//If we clicked on page one..
if($page==1)
{
//if clicked below 5 then counting starts with 1 and end on 10...
if($page <= 5)
{
$p=1;
$j=$page + 9;
for($i = $p; $i <= $j; $i++)
{
echo "<a href=\"pageName.php?page=$i&searchby=$scropt&keywo rds=$sctxt&selectcat=$selectcat\"><font face='Verdana, Arial, Helvetica, sans-serif' color='#FF6633' size='1'><b> " . $i ." <b></font></a>";
}
}
//else privious 5 pages and next 4 pages displayed.
else
{
$p=$page - 5;
$j=$page + 4;
for($i = $p; $i <= $j; $i++)
{
echo "<a href=\"pageName.php?page=$i&searchby=$scropt&keywo rds=$sctxt&selectcat=$selectcat\"><font face='Verdana, Arial, Helvetica, sans-serif' color='#FF6633' size='1'><b> " . $i ." <b></font></a>";
}
}
echo $Next;
}
elseif($page==$total_pages)
{
echo $Prev;
$p=$page - 9;
$j=$page;
for($i = $p; $i <= $j; $i++)
{
echo "<a href=\"pageName.php?page=$i&searchby=$scropt&keywo rds=$sctxt&selectcat=$selectcat\"><font face='Verdana, Arial, Helvetica, sans-serif' color='#FF6633' size='1'><b> " . $i ." <b></font></a>";
}
}
else
{
echo $Prev;
if($page <= 5)
{
$p=1;
$j=10;
for($i = $p; $i <= $j; $i++)
{
echo "<a href=\"pageName.php?page=$i&searchby=$scropt&keywo rds=$sctxt&selectcat=$selectcat\"><font face='Verdana, Arial, Helvetica, sans-serif' color='#FF6633' size='1'><b> " . $i ." <b></font></a>";
}
}
else
{
if($page == $total_pages - 3)
{
$p=$page - 6;
$j=$total_pages;
for($i = $p; $i <= $j; $i++)
{
echo "<a href=\"pageName.php?page=$i&searchby=$scropt&keywo rds=$sctxt&selectcat=$selectcat\"><font face='Verdana, Arial, Helvetica, sans-serif' color='#FF6633' size='1'><b> " . $i ." <b></font></a>";
}
}
elseif($page == $total_pages - 2)
{
$p=$page - 7;
$j=$total_pages;
for($i = $p; $i <= $j; $i++)
{
echo "<a href=\"pageName.php?page=$i&searchby=$scropt&keywo rds=$sctxt&selectcat=$selectcat\"><font face='Verdana, Arial, Helvetica, sans-serif' color='#FF6633' size='1'><b> " . $i ." <b></font></a>";
}
}
elseif($page == $total_pages - 1)
{
$p=$page - 8;
$j=$total_pages;
for($i = $p; $i <= $j; $i++)
{
echo "<a href=\"pageName.php?page=$i&searchby=$scropt&keywo rds=$sctxt&selectcat=$selectcat\"><font face='Verdana, Arial, Helvetica, sans-serif' color='#FF6633' size='1'><b> " . $i ." <b></font></a>";
}
}
else
{
$p=$page - 5;
$j=$page + 4;
for($i = $p; $i <= $j; $i++)
{
echo "<a href=\"pageName.php?page=$i&searchby=$scropt&keywo rds=$sctxt&selectcat=$selectcat\"><font face='Verdana, Arial, Helvetica, sans-serif' color='#FF6633' size='1'><b> " . $i ." <b></font></a>";
}
}
}
echo $Next;
}
//end of paging....

Thanks
Praful.

-------------------------------------------------
When I was born, I was cryed and everyone around me was smiling.
Live our life so at the end, I am the one who is smiling and everyone around me is crying.

Last edited by prafulkr; 2008-02-18 at 09:03 AM.
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.0 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.0 (a popular PHP IDE) and NuCoder 1.4 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
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

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



All times are GMT +1. The time now is 04:41 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.