Jump to content

Archived

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

Shadow Hatake

How would I make a script make multiple pages

Recommended Posts

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.

[code]<?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);
?>[/code]

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

Share this post


Link to post
Share on other sites
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?

[code]<?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);
?>[/code]

Share this post


Link to post
Share on other sites
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. ^^;

Share this post


Link to post
Share on other sites
Perhaps you didn't realize, but this thread is 5 years old.

Share this post


Link to post
Share on other sites

×

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.