Hi guys,
I got this search engine that’s supposed to go into a database according to a country the client selects and output data pertaining to that specific country with pagination.
The data shows up if the submit button is clicked, but the pagination stops functioning since the “$country_form” is never reset and the mysql query doesn’t know where to pull the data from.
How can I tell the code to use the previously set “$country_form” (the one set after submit button was clicked) in order for the the pagination to work?
Please any help appreciated.
<?php
include ('connectionhost.php');
if($_POST['submit'])
{
$country_form = $_POST['inputcountry'];
}
else
{
$country_form =
}
//grab POST data
//max displayed per page
$per_page = 2;
//get start variable: this determines where we're starting from when extracting data from database
$start = $_GET['start'];
//count records: this will count how many rows are returned
$record_count = mysql_num_rows(mysql_query("SELECT * FROM mainweb WHERE country='$country_form'"));
//count max pages
$max_pages = $record_count / $per_page; //may come out as decimal
if(!$start)
$start = 0;
//display data //add between mainweb and LIMIT: WHERE country='$country_form'
$get = mysql_query("SELECT * FROM mainweb WHERE country='$country_form' LIMIT $start, $per_page");
while ($row = mysql_fetch_assoc($get))
{
//get data
$firstname = $row['firstname'];
$lastname = $row['lastname'];
echo $firstname."(".$lastname.")<br />";
}
//setup prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;
//show prev button
if(!($start<=0))
echo"<a href='pagination.php?start=$prev'>Prev</a> ";
//show page numbers: $x< is the condition. $x=$x is the increment
//set variable for first page
$i=1;
for ($x=0;$x<$record_count;$x=$x+$per_page)
{
if($start!=$x)
echo "<a href='pagination.php?start=$x'>$i</a> ";
else
echo "<a href='pagination.php?start=$x'><b>$i</b></a> ";
//++ means to add 1 to a value
$i++;
}
//show next button
if(!($start>=$record_count-$per_page))
echo"<a href='pagination.php?start=$next'>Next</a>" ;
?>
<form action="pagination.php" method="post">
<div style="text-align: center;">Country:
<select name="inputcountry"><option><?php echo $country_form;?></option><option>---</option><option>Brazil</option><option>Canada</option><option>Chile</option><option>Ecuador</option><option>England</option><option>France</option><option>Israel</option><option>Mexico</option><option>South Africa</option><option>USA</option></select>
<br />
<p><input name="submit" value="Search" type="submit" /> </p>
</div>
</form>