Forum Moderators: coopster
I'm trying to fix the GET method path so that when i press the next
button of the page it will retain the value.
This is the link that i'm trying to fix.
<snip>
Below that page you can see the browse row by five or by ten.
When the user choose the row by 10 for instance the next button
value of the paging should retain "and display the browse row by 10"
whatever page the user wanted to select.
could you show me how to change the path for GET for this in these codes below? so that it will retain the selected value.
[codes]
<?php
include "opendb.php";
// how many rows to show per page
#$order = isset($_GET['order'])? $_GET['order'] : 'desc';
$rowsPerPage = isset($_GET['row'])? $_GET['row'] : 25;
$rowsPerPage = (int)($rowsPerPage);
/*
if(isset($_GET['row'])) {
if($_GET['row']=='25')
$rowsPerPage=25;
if($_GET['row']=='50')
$rowsPerPage=50;
} elseif($row=='') {
$rowsPerPage=25;
}
*/
#$rowsPerPage = 25;
$xpose_Rec = $rowsPerPage;
$i = 1;
// by default we show first page
$pageNum = 1;
$cnt=1;
echo "rowsPerPage: " . $rowsPerPage;
echo " xpose_Rec: " . $xpose_Rec;
//row per page
#if( $_GET['rowsPerPage'] )
#$rowsPerPage = (int)($_GET['rowsPerPage']);
// if $_GET['page'] very important baby
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$ctr=0;
$query = "SELECT * FROM cclp_players LIMIT $offset, $xpose_Rec";
$result = mysql_query($query) or die('Error, query failed');
// print the student info in table
echo "<div align='center'>";
echo "<p>";
//get default directories
//echo ('<a href="img_info.php?current_file='.$current_file.'"><img src="'.$current_img.'" border="1"><h1> </h1></a>');
$images_dir = 'http://' . $_SERVER['HTTP_HOST'] . '/dev/tmt/images/teams/';
$images_dir2 = 'http://' . $_SERVER['HTTP_HOST'] . '/dev/tmt/images/';
$images_pic2 = $images_dir2 . "golemavatar.gif";
$cnt2=0;
echo "<table border='0' width='700px' cellspacing='0' cellpadding='0' bgcolor=''>";
while(list($id, $lname, $fname, $birthday, $email, $hphone, $wphone, $address, $teamid, $position, $number, $info, $taglia, $sport1, $sport2, $sport3, $citta, $likedin, $photo) = mysql_fetch_array($result)) {
$images_pic = $images_dir . $photo;
if($cnt2==5) {
echo "<tr>";
}
echo "<td width='20px' valign='top'>";
//display the image
//<a href="'.$images_pic[""].'" onmouseover="alert("'.$images_pic["what_ever"].'")>
if($photo!=""){
echo ('
<a href="'.$images_pic[""].'">
<img src="'.$images_pic.'" alt="testing" width="118" height="118" border="2"/></a>');
}
//display temporary image if $photo is empty.
if($photo==""){
echo ('<img src="'.$images_pic2.'" width="118" height="118" border="2"/>');
}
echo "<b><br>$lname</b>";
echo "</td>";
$cnt2++;
if($cnt2==5) {
echo "</tr>";
$cnt2=0;
}
}
echo "</table>";
echo "</div>";
echo "</p>";
echo "<br>";
#######################
# Displaying previous and next links #
#######################
// how many rows we have in database
$query = "SELECT COUNT(id) AS numrows FROM cclp_players";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numRows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numRows/$xpose_Rec);
$self = $_SERVER['PHP_SELF'];
// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link
// print 'previous' link only if we're not
// on page one
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
$prev = ' [Prev] '; // we're on page one, don't enable 'previous' link
$first = ' [First Page] '; // nor 'first page' link
}
// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
#<a href="forumdisplay.php?f=34&daysprune=-1&order=desc&sort=views" rel="nofollow">Views</a>
#$next = " <a href=\"$self?page=$page\">[Next]</a> ";
$next = " <a href=\"$self?page=$page?rowsPerPage=$rowsPerPage\" rel=\"nofollow\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' [Next] '; // we're on the last page, don't enable 'next' link
$last = ' [Last Page] '; // nor 'last page' link
}
// print the page navigation link
echo "<center>";
echo $first . $prev . " Page <strong>$pageNum</strong> of <strong>$maxPage</strong> " . $next . $last;
echo "</center>";
####################################################
#P A G I N G stop #
####################################################
echo "<br>";
?>
<form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>">
<table align="center" border="0" width="400">
<tr>
<td width="475" colspan="4" bgcolor="#00FF00"><b>Browse by number of rows.</b></td>
</tr>
<tr>
<td width="118" bgcolor="#FFFF00">
<p align="center"><input type="radio" value="25" name="row"></td>
<td width="119" bgcolor="#FFFF00">
<p align="left">5 rows</td>
<td width="119" bgcolor="#FFFF00">
<p align="center"><input type="radio" value="50" name="row"></td>
<td width="119" bgcolor="#FFFF00">
<p align="left">10 rows</td>
</tr>
<tr>
<td width="475" colspan="4" bgcolor="#00FF00"><b>Filter</b></td>
</tr>
<tr>
<td width="118" bgcolor="#FFFF00">
<p align="center"><select size="1" name="team"></select></p>
</td>
<td width="119" bgcolor="#FFFF00">
<p align="left">By Team</td>
</td>
<td width="119" bgcolor="#FFFF00">
<p align="center"><select size="1" name="team"></select></p>
</td>
<td width="119" bgcolor="#FFFF00">
<p align="left">By Division</td>
</td>
</tr>
<tr>
<td width="118" bgcolor="#FFFF00"> </td>
<td width="119" bgcolor="#FFFF00"> </td>
<td width="119" bgcolor="#FFFF00"> </td>
<td width="119" bgcolor="#FFFF00"> </td>
</tr>
</table>
<p align="center"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
[/codes]
Thanks very much advance.
[edited by: eelixduppy at 12:59 am (utc) on Oct. 24, 2007]
[edit reason] no URLs, please [/edit]
Are you saying that when you make a new request you want the same value to be there in the $_GET array?
If you do then either you will need to set that value in the script i.e.
$_GET['whatever'] = 'something';
But this seems a little bit of a strange use of $_GET, as you could just use $whatever = 'something';
As the $_GET array will change on each submission if you want variables that can be set and called on pages further down the line then you could think about sessions.