Jump to content

previous & next link problem


serious1234

Recommended Posts

i want to make a page that display database contents as follows. at the top of the page i want to show details of the selected message the name of the author , date and subject and the message itself with a PREVIOUS PAGE | NEXT PAGE under them and after that there is a list of all the messages. my question is how could i do it that when someone click on a link on the list or click previous or next page button to get the right information. i just did that but my problem is with the order because in the database it happened that i dropped some rows and there was a difference inorder that makes wrong information when clicking on a specific link. this is the code and i hope you could help me. pardon me guys because i am new to php programming and you might find odd things in my codes.

here is the code

 

code:

<?php

include 'connect.php';

$page1=24;

if(isset($_GET['message'])){$page1=$_GET['message'];

 

}

 

// how many rows to show per page

$rowsPerPage =1;

 

// by default we show first page

$pageNum = 1;

 

// if $_GET['page'] defined, use it as page number

if(isset($_GET['page']))

{

    $pageNum = $_GET['page'];

}else {$pageNum=$page1-23;}

// counting the offset

$offset = ($pageNum - 1) * $rowsPerPage;

 

$query  = "SELECT * FROM comments LIMIT $offset, $rowsPerPage";

$result = mysql_query($query) or die('Error, query failed');

 

// print the random numbers

$row = mysql_fetch_array($result);

 

    echo $row['date_auto'] . '<br>';

    echo $row['name'] . '<br>';

    echo $row['subject'] . '<br>';

    echo $row['comment'] . '<br>';

    $aqeel=$row['autoID'];

 

echo '<br>';

if(!isset($_GET['page'])){$aqeel=$message;}

 

// how many rows we have in database

$query  = "SELECT COUNT(comment) AS numrows FROM comments";

$result  = mysql_query($query) or die('Error, query failed');

$row    = mysql_fetch_array($result, MYSQL_ASSOC);

$numrows = $row['numrows'];

 

// how many pages we have when using paging?

$maxPage = ceil($numrows/$rowsPerPage);

 

// print the link to access each page

$self = $_SERVER['PHP_SELF'];

 

 

 

// creating previous and next link

// plus the link to go straight to

// the first and last page

 

if ($pageNum > 1)

{

    $page = $pageNum - 1;

    $prev = " <a href=\"$self?page=$page\">Prev Message</a> ";

 

 

}

else

{

    $prev  = ' '; // we're on page one, don't print previous link

 

}

 

if ($pageNum < $maxPage)

{

    $page = $pageNum + 1;

    $next = " <a href=\"$self?page=$page\">Next Message</a> ";

 

}

else

{

    $next = ' '; // we're on the last page, don't print next link

    $last = ' '; // nor the last page link

}

 

// print the navigation link

echo  $prev  ."|". $next ;

echo "<br>";

$query1  = "SELECT * FROM comments LIMIT  25 ";

$result1 = mysql_query($query1) or die('Error, query failed');

while($row1 = mysql_fetch_array($result1))

{

if ($row1[autoID]==$aqeel ){

print "<b>$row1[subject]</b><br>";}else{print "<a href='Copy of Copy of paging.php?message=$row1[autoID]'>$row1[subject]</a><br>";}

}

 

?>

 

 

 

 

my database tables are

 

 

-- phpMyAdmin SQL Dump

-- version 2.9.1.1

-- http://www.phpmyadmin.net

--

-- Host: localhost

-- Generation Time: Apr 28, 2007 at 02:57 AM

-- Server version: 5.0.27

-- PHP Version: 5.2.0

--

-- Database: `serious`

--

 

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

 

--

-- Table structure for table `comments`

--

 

CREATE TABLE `comments` (

  `autoID` int(10) NOT NULL auto_increment,

  `name` varchar(64) NOT NULL,

  `email` varchar(64) NOT NULL,

  `subject` varchar(100) NOT NULL,

  `status` enum('seen','hidden') NOT NULL,

  `comment` text NOT NULL,

  `date_auto` int(10) NOT NULL,

  `approved` enum('0','1','2') NOT NULL default '2',

  PRIMARY KEY  (`autoID`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=68 ;

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.