Jump to content

Can someone help me with pagination


impactdesign

Recommended Posts

I am new to php programming and I really need help getting a page to paginate. I have tried a bunch of codes found online, yet I can not get to merge with my current code. Here is the core of my code without pagination function. Can someone help me? Pleeeeeeeeeeeease????

 

<?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();
?>

Link to comment
https://forums.phpfreaks.com/topic/91388-can-someone-help-me-with-pagination/
Share on other sites

admin were the tutoral for pag on here gon please server down why

 

example needs tweeking but the idear there mate........

<?php

$connection = @mysql_connect('localhost', '*****', '*****');
if (!$connection) {
echo '<p>Unable to make database connection.</p>';
exit();
}

if (!@mysql_select_db('  ')) {
exit('<p>Unable to locate database.</p>');
}

$limit = 10;

$query_count = "SELECT count(*) FROM companyid_uks49179 WHERE
town='Bury St. Edmunds' AND category='sleep' AND priority='0'";
$result_count = mysql_query($query_count);

$totalrows = mysql_num_rows($result_count);

if(empty($page)){
$page = 1;
}

$limitvalue = $page * $limit - ($limit);

$query = "SELECT company FROM companyid_uks49179 WHERE town='Bury
St. Edmunds' AND category='sleep' AND priority='0' LIMIT $limitvalue,
$limit";

$result = mysql_query($query) or die("Error: " . mysql_error());

if(mysql_num_rows($result) == 0){
echo("Nothing to Display!");
}

$bgcolor = "#E0E0E0"; // light gray

echo("<table>");

while($row = mysql_fetch_array($result)){

echo $row['company']."<br />";

}

echo("</table>");

if($page != 1){
$pageprev = $page--;

echo("<a href=\"$PHP_SELF?page=$pageprev\">PREV".$limit."</a>
");
}else{
echo("PREV".$limit." ");
}

$numofpages = $totalrows / $limit;

for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a");
}
}

if(($totalrows % $limit) != 0){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a");
}
}

if(($totalrows - ($limit * $page))){
$pagenext = $page++;

echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</
a>");
}else{
echo("NEXT".$limit);
}

mysql_free_result($result);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.