Jump to content

Rolling to new page after so much data..


dacool25

Recommended Posts

Hey everybody!  I'm new to the PHP scene.  Right now I have a page that displays a bunch of blogs.  I borrowed thishttp://www.zimmertech.com/tutorials/php/25/comment-form-script-tutorial.php script to use and modified it so that it would work the way that I want it to.

 

Anyways,  Right now all that I have in my main blog page is:

 

<?php
require('/path/to/inc_rate.php');
getComments("1");
?>

 

I would like it so that after about 10 blogs, it creates a new page (Or something along the lines).  Is there a way of doing this?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/99181-rolling-to-new-page-after-so-much-data/
Share on other sites

Well I did that (thank you for the tip), and started using this page: http://www.vipercreations.com/tutorials.php?cat=PHP&id=19&act=view Now ofcourse, none of the variables match up or anything like that, so I tried putting in the ones that I know from my previous one, but all that shows up is the author of the page, not the actual story.

 

Here is the new one i am trying to get to paginate:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test</title>
</head>

<body>
<?php



$host = "localhost"; //your sql host, usually 'localhost'

$user = "myusername"; //username to connect to database

$pass = "mypassword"; //password to connect to database

$db = "mysite_news"; //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 = 1; //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")

{

$commentid = $_GET['commentid'];

$sql = mysql_query("SELECT * FROM comments WHERE commentid = '$commentid'");

while($r = mysql_fetch_array($sql))

{

$title = $r['title'];

$comment = $r['comment'];

$name = $r['name'];

echo "<div><p>$title</p><p>$name</p><p>$comment</p></div>";

}



}else{



//view all the news articles in rows

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


//the total rows in the table

$totalres = mysql_result(mysql_query("SELECT COUNT(commentid) AS tot FROM comments"),0);	

//the total number of pages (calculated result), math stuff...

$totalpages = ceil($totalres / $max); 

//the table

echo "<table><tr><td>Title</td><td>name</td></tr><tr>";

while($r = mysql_fetch_array($sql))

{

$commentid = $r['commentid'];

$title = $r['title'];

$name = $r['name'];


echo "<td><a href='index.php?act=view&commentid=$commentid'>$title</a></td><td>$name</td>";

}

//close up the table

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

for($i = 1; $i <= $totalpages; $i++){ 

//this is the pagination link

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

}

}



?>
</body>
</html>

 

and here is a SQL dump of my current database:

 

-- phpMyAdmin SQL Dump
-- version 2.11.4
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 02, 2008 at 09:55 AM
-- Server version: 5.0.45
-- PHP Version: 5.2.5

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `mysite_news`
--

-- --------------------------------------------------------

--
-- Table structure for table `comments`
--

CREATE TABLE `comments` (
  `commentid` int(11) NOT NULL auto_increment,
  `tutorialid` int(11) NOT NULL default '0',
  `name` text NOT NULL,
  `url` text NOT NULL,
  `comment` text NOT NULL,
  `email` text NOT NULL,
  `date` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`commentid`),
  KEY `tutorialid` (`tutorialid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=65 ;

--
-- Dumping data for table `comments`
--

INSERT INTO `comments` (`commentid`, `tutorialid`, `name`, `url`, `comment`, `email`, `date`) VALUES
(1, 1, 'Author Name', '', 'Body of article', '', '2008-04-01 14:07:28'),
(2, 1, 'Author Name', '', 'Body of article', '', '2008-04-01 14:08:22'),
(3, 1, 'Author Name', '', 'Body of article', '', '2008-04-01 14:28:03'),
(4, 1, 'Author Name', '', 'Body of article', '', '2008-04-01 14:29:16');

 

Can anyone help?

 

Thanks

 

P.S. I edited some of the content for privacy reasons.

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.