Hi im currently working on the display element of my embedded algorithm but really need to master pagination as viewing 100+ results is not appealing to the eye
i did as any idiot would do and googled "php pagination tutorials" and came across quite a selection of them but was not able to adapt any to my program .
The script im currently using is
<?php
require_once('auth.php');
require_once('config.php');
require_once('opendb.php');
session_start();
$user = $_SESSION['SESS_USERNAME'];
$User_id = $_SESSION['SESS_MEMBER_ID'];
// num to display per page
// the more records per page, the slower the page will load
$PerPage = 2;
// Number of page links displayed (on either side of current page)
$Page_Links = 2;
if ($pageNum < 1 || !$pageNum) $pageNum = 1;
/*****************************************/
function Do_Links($querystring) {
global $PerPage, $Page_Links, $pageNum, $num_rows, $PHP_SELF;
$num_pages = ceil($num_rows / $PerPage);
$start = ($pageNum > ($Page_Links + 1)) ? ($pageNum - $Page_Links) : 1;
$end = ($num_pages > ($pageNum + $Page_Links)) ? ($pageNum + $Page_Links) : $num_pages;
echo<<<myHTML
<table border=0 cellpadding=0 cellspacing=0 align=center>
<tr>
<td>
<font size=2 face=arial>
<a href="$PHP_SELF?pageNum=1&$querystring">First</a>
myHTML;
for ($i=$start; $i<$end; $i++) {
if ($i == $pageNum)
echo "\t<b>$i</b>\n";
else
echo "\t<a href=\"$PHP_SELF?pageNum=$i&$querystring\">$i</a>\n";
}
if ($end == $pageNum)
echo "<b>$end</b>\n";
else
echo "<a href=\"$PHP_SELF?pageNum=$end&$querystring\">$end</a>\n";
echo<<<myHTML
<a href="$PHP_SELF?pageNum=$num_pages&$querystring">Last</a>
</font>
</td>
</tr>
</table>
myHTML;
} //END Do_Links()
/*****************************************/
// Build the query
//$query = ("SELECT `base_id`,`match_id`,`base_rating`,`$base_rating`,`match_rating` FROM `compatibility` WHERE `base_id`=$User_id");
$query=("SELECT * from members");
$result = mysql_query($query) or die (mysql_error());
if (!$result) {
echo "<tr>\n";
echo "<td colspan='3' align='center'>\n";
echo "<b>Query Error:</b>" . mysql_error() . "<BR>\n";
echo "<b>Query:</b> $query\n";
echo "</td>\n";
echo "</tr>\n";
}
$num_rows = mysql_num_rows($result);
if ($num_rows == 0) {
echo "<tr>\n";
echo "<td colspan='3' align='center'>\n";
echo "<b>No matches found.</b>\n";
echo "<!--\n";
echo "Query Error:" . mysql_error() . "\n";
echo "Query: $query\n";
echo "-->\n";
echo "</td>\n";
echo "</tr>\n";
}
else {
// where do we start?
$pageNum = ($pageNum < 1) ? 1 : $pageNum;
$start = $PerPage * ($pageNum - 1);
// go there!
mysql_data_seek($result, $start);
}
for ($i=0; $i<$PerPage; $i++) {
if ($tmp = mysql_fetch_array($result)) {
extract($tmp);
echo " <tr>\n";
echo " <td>$member_id</td>\n";
echo " <td>$login</td>\n";
echo " <td>$dob</td>\n";
echo " </tr>\n";
echo "<br>";
}
}
echo "</TABLE>\n";
if ($num_rows > 0) {
// build a querystring
$querystring = "this=$this";
//pagenate it!
Do_Links($querystring);
}
?>
I used a rather basic select * from members but the problem is that it will view the first page correctly showing the results but if i click on any of the links i wont display the other results
for example if i click on the 2 the url will change to
http://localhost/1/test.php?pageNum=2&this=
but the first set of results will remain
Now from what little i know from php having "this=" is the problem and i see in the code
if ($num_rows > 0) {
// build a querystring
$querystring = "this=$this";
//pagenate it!
Do_Links($querystring);
}
It tries to assign '$this' but it never actually is been given a value so the function Do_links is passing an empty value
If any of you genii can give advice or even a simple basic tutorial i would be very thank full.
Cheers,
Pages.