Newbie here, I found a script to do pagination and got it to work for me. I have an html tempelate that i want to use the pagination script with but im not sure how the two integrate with eachother. Any help is greatly appreciated.
Thanks
-soianyc
Using my php pagination script in my html file
Moderator: General Moderators
How would i know how to do that??? I set up my tempelate with tables and such, and in four cells i want to put the code.
This is the pagination script that i used, found it online and works with my data. Im a little confused in how to embedd all of this???
Any guidelines would be greatly appreciated.
Thanks
This is the pagination script that i used, found it online and works with my data. Im a little confused in how to embedd all of this???
Code: Select all
<?php
// Database Connection
include 'connect.php';
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 10;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
$sql = mysql_query("SELECT * FROM pages LIMIT $from, $max_results");
while($row = mysql_fetch_array($sql)){
// Build your formatted results here.
echo $row['title']."<br />";
}
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pages"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<center>Select a Page<br />";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo "</center>";
?>Thanks
Just change your echos to variable declarations and then put them wherever you want on the page:
Code: Select all
<?
$prevs = "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a>";
$pages = "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a>";
$nexts = "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";}echo "</center>";
?>
<body>
<table width="500" align="center">
<tr>
<td colspan="3" align="center">My Pagination</td>
<tr>
<tr>
<td><?=$prevs;?></td>
<td align="center"><?=$pages;?></td>
<td align="right"><?=$nexts;?></td>
<tr>
</table>
</body>Not to my knowledge (any negatives)...I've always used it...although I'm sure someone out there will have some issues with it they'll let you know about.
for me however, I've never had problems with it (possibly doesn't work in older versions of php??)...dunno.
I don't think it works with <?php= though, only with <?= but I might be wrong and I'm too lazy to test it right now
for me however, I've never had problems with it (possibly doesn't work in older versions of php??)...dunno.
I don't think it works with <?php= though, only with <?= but I might be wrong and I'm too lazy to test it right now
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
<?= is call a short tag echo. It can easily be turned off, so it's best to avoid by always usingor use templates. 
Code: Select all
<your html here><?php echo 'foo'; ?>