Log in

View Full Version : PHP Pagination



PatrikIden
11-22-2011, 07:16 PM
Hi, i want to make a pagination to my DB data. Like the one on THIS site (botom right). Any code for that?

Thank's

/Patrik.

traq
11-23-2011, 03:54 AM
Your question is unclear.
Please provide more information, and be as specific as possible.
What do you want to accomplish? What have you already tried? What problems did you encounter?
Also, please be sure that you have included all relevant code and/or a link to the page in question.

pagination is simply a way to break up existing content into manageable sections. It doesn't involve working with databases (not directly, anyway; you might pull the content from a database, but that's a preliminary step and isn't strictly related).

Like the one [pagination] on THIS site (botom right).
I don't have any idea what it is you're referring to when you say that.

As far as finding code, you'll first need to figure out what it is you want to do. From there, you can determine what your question is.

PatrikIden
11-23-2011, 11:22 AM
OK i have a page whara i want to show DB data, now when the DB gets more and more entrys i whish to have a pagination "NEXT 1 2 3 4 5...PREVIUS". So this is what i'v tryed: but tgis is only giving me "NEXT and PREVIUS" links.



<?php

$databasename='****'; // Name of the database
$tablename='jobadd'; // Name of the table
$mysqladd='****'; // Address to the MySQL Server
$mysqluser='****'; // Your MySQL UserName
$mysqlpass='****'; // Your MySQL Password




if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
//we give the value of the starting row to 0 because nothing was found in URL
$startrow = 0;
//otherwise we take the value from the URL
} else {
$startrow = (int)$_GET['startrow'];
}
$query="SELECT * FROM jobadd ORDER BY Timestamp DESC LIMIT $startrow, 10";
echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+10).'">Nästa&nbsp;&nbsp;&nbsp;&nbsp;</a>';
$prev = $startrow - 10;

//only print a "Previous" link if a "Next" was clicked
if ($prev >= 0)
echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.$prev.'">Föregående</a>';


$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

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


?>


<div class="blogitem" style="display: block;">
<div class="blogdivider"><img src="./images/devider.gif" width="100%" height="1px" border="0"><br></div>
&nbsp;<font face="Arial" color="#666666" style="font-size:10px"><?php echo mysql_result($result,$i,"ID"); ?>&nbsp;|&nbsp;&nbsp;</font>&nbsp;<font face="Arial" color="#666666" style="font-size:10px">Datum:
<?php echo mysql_result($result,$i,"Time_of_submission"); ?></font>
<br><div class="blogsubject">&nbsp;<?php echo mysql_result($result,$i,"Vad"); ?>&nbsp;&nbsp;|&nbsp;&nbsp;<?php echo mysql_result($result,$i,"Var"); ?>
&nbsp;&nbsp;|&nbsp;&nbsp;<?php echo mysql_result($result,$i,"Postnr"); ?>&nbsp;&nbsp;|&nbsp;&nbsp;ID Kod: <?php echo mysql_result($result,$i,"Idkod"); ?></a><br></div>
<font face="Arial" color="#282828" style="font-size:13px"><br></font>
<br>
<font face="Arial" color="#FF0000" style="font-size:13px"><b>&nbsp;När skall Uppdraget börja:</b></font>
<br>
&nbsp;<?php echo mysql_result($result,$i,"När"); ?>
<a href="http://jobler.se/svara.php?ID=<?php echo mysql_result($result,$i,"ID"); ?>&Idkod=<?php echo mysql_result($result,$i,"Idkod"); ?>"><img src="images/senaste6_0217.png" id="svarShape3" alt="" title="" style="position:absolute;left:270px;border-width:0;width:280px;height:81px;"></a>
</div>
<br>
<font face="Arial" color="#FF0000" style="font-size:13px"><b>&nbsp;Uppdragets uppskattade pris:</b></font>
<br>
&nbsp;<?php echo mysql_result($result,$i,"Pris"); ?> kr
<br>
<br>
<br>
<br>
<br>
<font face="Arial" color="#FF0000" style="font-size:13px"><b>&nbsp;Beskrivning av uppdrag:</b></font>
<br>
&nbsp;<?php echo mysql_result($result,$i,"Beskrivning"); ?>
<br>
<br>
<br>
<br>



<?php
$i++;
endwhile;
?>
</body>
</html>