Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 05-10-2007, 07:32 PM   #1
Baseband Member
 
Dnsgm's Avatar
 
Join Date: Jan 2006
Posts: 61
Default php Pagination

Here's the code that i've been trying to work with. I have the table set but I have no idea how to use it...like uploading the files

PHP Code:
 <?php
      $host 
"localhost"//your sql host, usually 'localhost'
      
$user "........"//username to connect to database
      
$pass ".........."//password to connect to database
      
$db "......"//the name of the database

      
mysql_connect($host,$user,$pass) or die("ERROR:".mysql_error());

      
mysql_select_db($db) or die("ERROR DB:".mysql_error());



      
$max 10//amount of articles per page. change to what to want
      
$p $_GET['p'];
      if(empty(
$p))
      {
      
$p 1;
      }
      
$limits = ($p 1) * $max;

      
//view the news article!

      
if(isset($_GET['act']) && $_GET['act'] == "view")
 
      {

      
$id $_GET['id'];
      
$sql mysql_query("SELECT * FROM photo WHERE id = '$id'");

      while(
$r mysql_fetch_array($sql))
      {
      
$title $r['id'];

      
$story $r['body'];
      
$author $r['author'];

      echo 
"<div><p>$title</p><p>$author</p><p>$story</p></div>";
      }

      }
      else
      {

      
//view all the news articles in rows

      
$sql mysql_query("SELECT * FROM photo LIMIT ".$limits.",$max") or die(mysql_error());

      
//the total rows in the table

      
$totalres mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM photo"),0); 
      
//the total number of pages (calculated result), math stuff...
 
      
$totalpages ceil($totalres $max);

      
//the table

      
echo "<table><tr><td>Title</td><td>Author</td></tr><tr>";
      while(
$r mysql_fetch_array($sql))
      {
      
$id $r['id'];
      
$title $r['body'];
      
$author $r['author'];
      
      echo 
"<td><a href='test.php?act=view&id=$id'>$title</a></td><td>$author</td>";
      
      }
      
//close up the table

      
echo "</tr></table>";

      for(
$i 1$i <= $totalpages$i++){
 
      
//this is the pagination link

      
echo "<a href='test.php?p=$i'>$i</a>|";
 
      }

      }

      
?>
Dnsgm is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off



All times are GMT -5. The time now is 02:35 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0