i need to create a pagination code for php. i found many php codes around the web and found them very usefull, but never found one which really suited my needs.
What i need is:
1) i select which section i need to search for from a FORM, then i sumbit the result.
2) in the viewresult page you get the value of the section chosen via the $_POST function
$section =$_POST[section];
then the section is searched for from the MYSQL database
sql = ..... WHERE section=\"$section"\
Go to next page
<a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage§ion=$section'><img src=Pics/control_fastforward.png BORDER=0></a>
with the part of code where i need to go to next page i need to send the value of the section
the problem i am finding is that since it is refreshing on the same page the value of section is coming to "null" since the first value of section was taken from another page with the $_POST function.
is there a way how i can overcome this problem?
hope i explained my self:
the code is below
<?php
$section=$_POST[section];
connect to database
if (isset($_GET['pageno']))
{
$pageno = $_GET['pageno'];
}
else
{
$pageno = 1;
}
$query = "SELECT count(*) FROM news WHERE section like \"%$section%\" ";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
echo "SECTION: $section <br> ";
$rows_per_page = 2; // number of records to show per page
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
}
elseif ($pageno > $lastpage) {
$pageno = $lastpage;
}
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query2 = "SELECT * FROM news WHERE section like \"%$section%\" ORDER by id DESC $limit ";
$result2 = mysql_query($query2) or trigger_error("SQL", E_USER_ERROR);
while($nt2=mysql_fetch_array($result2))
{
$author = $nt2[author];
$section = $nt2[section];
$title = $nt2[title];
$msg = $nt2[msg];
echo $author
echo $section
echo $title
echo $msg
}
echo "<font face=Century Gothic size=2>Page $pageno of $lastpage</font> <br>";
if ($pageno == 1)
{
}
else
{
echo "<a href='{$_SERVER['PHP_SELF']}?pageno=1§ion=$section'><img src=Pics/control_start.png BORDER=0></a>\n ";
$prevpage = $pageno-1;
echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage§ion=$section'><img src=Pics/control_rewind.png BORDER=0></a>\n ";
}
if ($pageno == $lastpage)
{
}
else
{
$nextpage = $pageno+1;
echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage§ion=$section'><img src=Pics/control_fastforward.png BORDER=0></a>\n ";
echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage§ion=$section'><img src=Pics/control_end.png BORDER=0></a>\n ";
}
?>
What i need is:
1) i select which section i need to search for from a FORM, then i sumbit the result.
2) in the viewresult page you get the value of the section chosen via the $_POST function
$section =$_POST[section];
then the section is searched for from the MYSQL database
sql = ..... WHERE section=\"$section"\
Go to next page
<a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage§ion=$section'><img src=Pics/control_fastforward.png BORDER=0></a>
with the part of code where i need to go to next page i need to send the value of the section
the problem i am finding is that since it is refreshing on the same page the value of section is coming to "null" since the first value of section was taken from another page with the $_POST function.
is there a way how i can overcome this problem?
hope i explained my self:
the code is below
<?php
$section=$_POST[section];
connect to database
if (isset($_GET['pageno']))
{
$pageno = $_GET['pageno'];
}
else
{
$pageno = 1;
}
$query = "SELECT count(*) FROM news WHERE section like \"%$section%\" ";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
echo "SECTION: $section <br> ";
$rows_per_page = 2; // number of records to show per page
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
}
elseif ($pageno > $lastpage) {
$pageno = $lastpage;
}
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query2 = "SELECT * FROM news WHERE section like \"%$section%\" ORDER by id DESC $limit ";
$result2 = mysql_query($query2) or trigger_error("SQL", E_USER_ERROR);
while($nt2=mysql_fetch_array($result2))
{
$author = $nt2[author];
$section = $nt2[section];
$title = $nt2[title];
$msg = $nt2[msg];
echo $author
echo $section
echo $title
echo $msg
}
echo "<font face=Century Gothic size=2>Page $pageno of $lastpage</font> <br>";
if ($pageno == 1)
{
}
else
{
echo "<a href='{$_SERVER['PHP_SELF']}?pageno=1§ion=$section'><img src=Pics/control_start.png BORDER=0></a>\n ";
$prevpage = $pageno-1;
echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage§ion=$section'><img src=Pics/control_rewind.png BORDER=0></a>\n ";
}
if ($pageno == $lastpage)
{
}
else
{
$nextpage = $pageno+1;
echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage§ion=$section'><img src=Pics/control_fastforward.png BORDER=0></a>\n ";
echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage§ion=$section'><img src=Pics/control_end.png BORDER=0></a>\n ";
}
?>