Tengo un formulario con un select que seleccionas una categoria, del 1 al 8, cuando elegis la categoria imprime los resultados y se hace la paginacion, el problema es que cuando paso de pagina se actualiza la pagina y el select vuelve al valor por default que es "seleccione una categoria", que puedo hacer? dejo el codigo
partido.php
Código:
buscar.php<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="partido.css"/>
</head>
<script>
function showUser(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","buscar.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="contenedor">
<nav>
<a href="index.php" class="linknav">Inicio</a> |
<a href="registro.php" class="linknav">Registrate</a> |
<a href="" class="linknav">Buscar Partido</a>
</nav>
<div id="cuerpo">
<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Selecciona categoria</option>
<option value="8">8</option>
<option value="7">7</option>
<option value="6">6</option>
<option value="5">5</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
</form>
<br>
<div id="txtHint"></b></div>
</div>
</div>
</body>
</html>
Código:
Gracias! <!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
$q = intval($_GET['q']);
//Iniciacion de la paginacion
if(isset($_REQUEST['pos']))
{
$inicio=$_REQUEST['pos'];
}
else
{
$inicio=0;
}
//Conectamos con la base de datos
$con = mysqli_connect('localhost','root','kavetoda31','padel');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"padel");
$sql="SELECT * FROM PAREJAS WHERE CATEGORIA = '".$q."' LIMIT $inicio,2";
$result = mysqli_query($con,$sql);
//Imprimimos los resultados en una tabla
echo "<table border=1>
<tr>
<th>Drive</th>
<th>Reves</th>
<th>Facebook</th>
<th>Categoria</th>
<th>Zona</th>
</tr>";
//Contamos los registros impresos
$impresos=0;
while($row = mysqli_fetch_array($result)) {
$impresos++;
echo "<tr>";
echo "<td>" . $row['NOMBREDRIVE'] . "</td>";
echo "<td>" . $row['NOMBREREVES'] . "</td>";
echo "<td>" . $row['FACEBOOK'] . "</td>";
echo "<td>" . $row['CATEGORIA'] . "</td>";
echo "<td>" . $row['ZONA'] . "</td>";
echo "</tr>";
}
echo "</table>";
if($inicio==0)
{
echo "Anteriores";
}
else
{
$anterior=$inicio-2;
echo "<a href=\"partido.php?pos=$anterior\">Anteriores</a>";
}
if($impresos==2)
{
$proximo=$inicio+2;
echo "<a href=\"partido.php?pos=$proximo\">Siguientes</a>";
}
else
{
echo "Siguientes";
}
mysqli_close($con);
?>
</body>
</html>


