It is a self-submitting Form. I have 3 independent Select lists whose selected values are passed as the WHERE parameters for the sql query.
When I click on the button, all data are displayed just fine, well LIMITed, and the link pages are below. But:
When I get to click on the page links, the result set and all the links disappear from sight (only the select lists remain in sight). I believe it is related to the isset condition that, if the values have not been set, display the form, if the values have been set, then process the form. So, the first result set displays correctly, but when you try to go to the second page my form interprets that the Select Lists are not set because they are reset and because i have not clicked on the button if i click on the links instead and therefore, it wipes out everything that it not an html Form.
There is no error in the paginating code. The error is in how I link this form with this paginating method. And I can’t get to know how I should.
if (isset($_POST['submitted'])) { /***************IF IT IS SET, WE PROCESS THE VALUES*************************/
$oldcountry = FALSE;
$oldfrom = FALSE;
$oldinto = FALSE;
// Here just checking that all variables have been selected
if (isset($_POST['country']))
{
$oldcountry = $_POST['country'];
$country = filter_var($oldcountry, FILTER_SANITIZE_STRING);
}
else {
echo 'Please, select a country';
}
if (isset($_POST['from_language']))
{
$oldfrom = $_POST['from_language'];
$from_language = filter_var($oldfrom, FILTER_SANITIZE_STRING);
}
else {
echo 'no has metido el from language';
}
if (isset($_POST['into_language']))
{
$oldinto = $_POST['into_language'];
$into_language = filter_var($oldinto, FILTER_SANITIZE_STRING);
}
// so, once we have selected them and clicked the button, we go for the query
// and paginate the results
require_once('bdd1.php');
$per_page = 6;
$pages_query = mysql_query("SELECT COUNT(FName)
FROM work_assignment, developer
WHERE AES_DECRYPT(country, 'elperrodesanroquenotienerabo') = '".$country."'
AND from_language = '".$from_language."'
AND into_language = '".$into_language."'
AND work_assignment.developer_id = developer.developer_id
ORDER BY FName ASC ");
$pages = ceil (mysql_result($pages_query, 0) /$per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
$query = mysql_query("SELECT FName
FROM work_assignment, developer
WHERE AES_DECRYPT(country, 'elperrodesanroquenotienerabo') = '".$country."'
AND from_language = '".$from_language."'
AND into_language = '".$into_language."'
AND work_assignment.developer_id = developer.developer_id
ORDER BY FName ASC LIMIT $start, $per_page");
while ($query_row = mysql_fetch_assoc($query)){
echo '<p>', $query_row['FName'], '</p>';
}
if ($pages >=1) {
for($x = 1; $x <=$pages; $x++){
echo '<a href="?page='.$x. '">'.$x.'</a> ';
}
}
} /************* END OF IF ISSET TO PROCESS *******************************/
?>
UPDATE UPDATE
After all the help, I managed to write a URL string that makes the page links work. Yet, still I need to tweak it as I hardcoded the name of the country (basically Estonia) instead of embedding the variable that represents it, but I can’t make that URL properly be written:
This works:
echo '<a href="?country=Estonia&from_language=Russian&into_language=Latvian&submitted=true&
page='.$x. '">'.$x.'</a> ';
I would just need to replace Estonia by $country, and Russian by $from_language and Latvian by $into_language. But I have tried all possible combinations of single and double quotes and dots and I get syntax errors. Does anybody know how to write that?
$_POST values are only set if information is sent with a POST request, for example your has most likely method=POST. When you submit your form with method POST (button=submit) the $_POST values are set. Whenever you klick another link, only a request for a new page will be sent to the server.
If you need the information to be available after the first form submit, you should use a Session. (http://php.net/manual/de/features.sessions.php)
Sessions are stored for each client (webbrowser) and are available until the session times out (please see manual). You would have to set the session variables the first time the form gets submitted. Afterwards you can use the values from the session.
/Edit
If you do not want to use a session, you could add the filter criteria as url parameters (index.php?groupby=country) to the normal links. They would then be accessed with $_GET.