Hello,
I've posted my question on a few boards, but I did not get the answer yet.
I used the search, and I found some posts with similar problems, but without an answer that I could use.
I've been rewriting my script for a couple of days now, and honestly I don't know anymore what I tried and what not, so I will tell you what my most current version does and should do.
I am displaying a form, to create a simple query. The fields are all sticky.
Based on the user's choice, the result of the query is displayed in a table.
Now, I want 2 things.
First to paginate results, and to make the heading hyperlinked for sorting purposes.
The problem is, that after I click on next page, the query is lost. Currently, I am sending the queries in the url, and they arrive, but I still can not go to the next page.
The only way to actually see the result on the next page is if I after I click on the "next", I have to click the submit button of the form still displayed underneath the table. Can you think of any way to make this work?
I will attach the code, the form at the bottom, and the sql for the tables, if you want to create them locally.
Thank you in advance!
S.
EDIT
the script is too long, I will attach it to the post
here is just the part of it
<?php
// this is the problem
if(isset($_POST['submitted']))
{
// initialize error array
$errors = array();
echo $query1;
echo "<br>$q";
$query1 = "SELECT * FROM asset ";
// check the fields
// here checking...
// add the sorting order to the query
$query .= " ORDER BY $order_by LIMIT $start, $display";
$query1 .= $query;
$query2 = "SELECT COUNT(*) FROM asset " . $query;
}
else if(isset($_GET['submitted']))
{
$query1 = stripslashes($_GET['query1']);
$query2 = stripslashes($_GET['query2']);
}
if(empty($errors))
{
// if here everything is fine
// make the query
$result = @mysql_query($query1);
echo $result;
if($result)
{
// Create a table.
// here table
// Fetch the results from the database.
while ($row = mysql_fetch_array($result))
{
//here the results
}
// determine how many pages are there
if(isset($_GET['np']))
{
$num_pages = $_GET['np'];
echo "<br>$num_pages";
}
else
{
$result2 = @mysql_query($query2);
$row2 = mysql_fetch_array($result2, MYSQL_NUM);
$num_records = $row2[0];
echo "<br><br>";
echo $num_records;
// calculate the number of pages
if($num_records > $display)
{
$num_pages = ceil($num_records/$display);
}
else
{
$num_pages = 1;
}
}// end of number pages IF
echo '</TABLE><br><br>';
if($num_pages > 1)
{
echo '<br /><p>';
// determine what page the script is on
$current_page = ($start/$display) + 1;
// if not the first, make a previous link
if($current_page != 1)
{
echo '<a href = "'. $_SERVER['PHP_SELF']. '?submitted=true&query1='.$query1.'&query2='.$query2.'&s=' . ($start - $display) .
'&np=' . $num_pages . '&sort=' . $sort . '">Previous</a> ';
}
// make all the numbered pages
for($i = 1; $i <= $num_pages; $i++)
{
if($i != $current_page)
{
echo '<a href = "'. $_SERVER['PHP_SELF']. '?submitted=true&query1='.$query1.'&query2='.$query2.'&s=' .
(($display * ($i - 1))) . '&np=' . $num_pages .
'&sort=' . $sort . '">' . $i . '</a> ';
}
else
{
echo $i . ' ';
}
}
// if it is not the last page, make a next link
if($current_page != $num_pages)
{
echo '<a href = "'. $_SERVER['PHP_SELF']. '?submitted=true&query1='.$query1.'&query2='.$query2.'&s=' . ($start + $display) .
'&np=' . $num_pages . '&sort=' . $sort . '">Next</a>';
}
echo '</p>';
}// end of links section
} //end of if result
}
else if($errors != "")
{
$query1 = "";
// report the errors
echo "<h1>Error!</h1><br />
The following error(s) occured:<br />";
foreach($errors as $msg)
{
echo " - $msg<br />\n";
}
echo "Please try again.<p></p>";
} // end of if empty errors
include('./includes/formselect.inc');
?>