Shadow Hatake Posted February 25, 2006 Share Posted February 25, 2006 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]<?phprequire("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. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 25, 2006 Share Posted February 25, 2006 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]<?phprequire("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 " ";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] Quote Link to comment Share on other sites More sharing options...
Shadow Hatake Posted February 25, 2006 Author Share Posted February 25, 2006 Yea it makes all the html easier to manage...well for me at least. Quote Link to comment Share on other sites More sharing options...
Shadow Hatake Posted February 25, 2006 Author Share Posted February 25, 2006 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. ^^; Quote Link to comment Share on other sites More sharing options...
tibberous Posted February 24, 2011 Share Posted February 24, 2011 http://www.phpeasystep.com/phptu/29.html Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 25, 2011 Share Posted February 25, 2011 Perhaps you didn't realize, but this thread is 5 years old. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.