Jump to content


Photo

How would I make a script make multiple pages


  • Please log in to reply
5 replies to this topic

#1 Shadow Hatake

Shadow Hatake
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 25 February 2006 - 06:24 PM

Okay so my news script is set to view only 10 pieces of news. But I want it so that it starts a new page once I have more than 10 pieces of news.

<?php
require("functions.php");
include("dbconnect.php");

session_start();

head1();
body1();
new_temp();
sotw();
navbar();
      
$start = 0;
$display = 10;
$query = "SELECT * FROM news ORDER BY id DESC LIMIT $start, $display";
$result = mysql_query( $query );

if ($result) {
    while( $row = @mysql_fetch_array( $result, MYSQL_ASSOC ) ) {
        news_box( $row['news'], $row['title'], $row['user'], $row['date'], $row['id'] );
    }
    mysql_free_result($result);
} else {
    news_box( 'Could not retrieve news entries!', 'Error', 'Error', 'Error');
}
                   
footer();

mysql_close($link);
?>

I tried a few things but they failed....miserably.

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 25 February 2006 - 08:28 PM

This should work. You'll probably have to adjust it some to make it display where you want.

Is there a reason you are putting all of your html into functions?

<?php

require("functions.php");
include("dbconnect.php");

session_start();

head1();
body1();
new_temp();
sotw();
navbar();
    
$start = $_GET['start'];
if ($start == "" || $start < 0) {
    $start = 0;
}
$display = 10;

$query = "SELECT * FROM news ORDER BY id DESC LIMIT $start, $display";
$result = mysql_query($query);

if ($result) {
    while( $row = @mysql_fetch_array( $result, MYSQL_ASSOC ) ) {
        news_box( $row['news'], $row['title'], $row['user'], $row['date'], $row['id'] );
    }
    mysql_free_result($result);
} else {
    news_box( 'Could not retrieve news entries!', 'Error', 'Error', 'Error');
}

echo '<div style="text-align: center">';
if ($start > 0) {
    echo "<a href=\"" . $_SERVER['PHP_SELF'] . "&start=" . $start - 10 . "\">Prev page</a>"; 
}
echo "&nbsp;&nbsp;";
if (($start + 10) < mysql_num_rows($result);) {
    echo "<a href=\"" . $_SERVER['PHP_SELF'] . "&start=" . $start + 10 . "\">Next page</a>"; 
}
echo '</div>';
           
footer();

mysql_close($link);
?>


#3 Shadow Hatake

Shadow Hatake
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 25 February 2006 - 09:22 PM

Yea it makes all the html easier to manage...well for me at least.

#4 Shadow Hatake

Shadow Hatake
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 25 February 2006 - 09:32 PM

well i tested it by replacing the 10's with 3's and it won't show the next/prev page at bottom, and it seems to be adding them above the last news box.

EDIT: Well after palying with a little, it shows the next/prev page thing. but now how do I get it to show after last piece of news? :/

ANOTHER EDIT: I created 2 footer functions. And that fixed the placement problem. Thanks for the code. ^^;

#5 tibberous

tibberous
  • Members
  • PipPipPip
  • Advanced Member
  • 1,188 posts

Posted 24 February 2011 - 11:55 PM

http://www.phpeasyst...m/phptu/29.html

#6 Pikachu2000

Pikachu2000
  • Staff Alumni
  • I hate everything.
  • 11,384 posts
  • LocationFuture Independent Republic of Texas
  • Age:106

Posted 25 February 2011 - 12:02 AM

Perhaps you didn't realize, but this thread is 5 years old.

"Java" is to "Javascript" about the same as "fun" is to "funeral".

Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf *

Random Quote: "

Remember, you're unique. Just like everybody else!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users