FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Next\previous button on news system





ranzon
Hi, i have a code to print news..
I want to print 6 news on each site, and have next\previous buttons.
But heres the problem: i don't have a clue how to make that..

my code to print 6 news:
Code:
<?php
include("db.php");
$query="SELECT * FROM nyheter ORDER BY id DESC LIMIT 0,6";
$result=mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result);
mysql_close();

$i=0;
while ($i < $num) {

$nyhet=nl2br(mysql_result($result,$i,"nyhet"));
$picurl=mysql_result($result,$i,"pic");
$topic=mysql_result($result,$i,"topic");
?>
<table width="592" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="163" height="25" valign="top">Topic:</td>
<td width="429" valign="top"><?php echo("$topic"); ?></td>
</tr>
<tr>
<td height="168" valign="top"><img src="<?php echo("$picurl"); ?>" height="168" width="163"></td>
<td valign="top"><?php echo("$nyhet"); ?></td>
</tr>
</table>
<?php
$i++;
}
?>

Please help me
BlackSkad
Code:
if (isset($_GET['start']) && is_numeric($_GET['START'])) {
   $start = $_GET['start']
}else{
   $start = 0;
}
$query="SELECT * FROM nyheter ORDER BY id DESC LIMIT ".$start.",6";


Just replace your query this piece of code. It will first look for a GET_var named start. This is the index from the first result. Then it will do the query, starting from $start and for 6 item.
A link to the first 6 items looks the same as before:
Code:
<a href="yournews.php">Latest News</a>

A link to a previous page will look like: (link for next page looks the same but with $start+6)
Code:
<a href=\"yournews.php?start=".$start-6."\">previous</a>


That should do the trick Smile
ranzon
BlackSkad wrote:
Code:
if (isset($_GET['start']) && is_numeric($_GET['START'])) {
   $start = $_GET['start']
}else{
   $start = 0;
}
$query="SELECT * FROM nyheter ORDER BY id DESC LIMIT ".$start.",6";


Just replace your query this piece of code. It will first look for a GET_var named start. This is the index from the first result. Then it will do the query, starting from $start and for 6 item.
A link to the first 6 items looks the same as before:
Code:
<a href="yournews.php">Latest News</a>

A link to a previous page will look like: (link for next page looks the same but with $start+6)
Code:
<a href=\"yournews.php?start=".$start-6."\">previous</a>


That should do the trick Smile


Thank you.. that worked... <3

but is it possible to count how many pages it is, and print them to Question Wink
ganbate
ranzon wrote:

Thank you.. that worked... <3

but is it possible to count how many pages it is, and print them to Question Wink


to count how many pages just use :

Code:

$num_page = $num/6;
ranzon
ganbate wrote:

to count how many pages just use :

Code:

$num_page = $num/6;


uhm if i have 1 page is it really suppose tu return that it is 0.166666666667 pages?
Related topics
Azkabanweb.tk
Web design
Report button/Warning System/Deal with tide of crud
Which is the best content management software
Want a news script which doesnt use MySQL?
Coranto - News system
[news].[tecg]Últimas Vulnerabilidades
news system with login for more than 1 user.
News system with mySQL database.
Problem installing a news system
[Community Project] Easy Simple Content Management System
News system
News script
I need a open source news system .
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.