Buenasss,
Tengo una salida por pantalla en un select que muestra todos los paises, y recoge el país que ha seleccionado el usuario, y otro con la categoría y así con muchos más filtros y recarga la página d la siguiente manera:
Código PHP:
Ver originalif (isset ($_POST['CountryInput'])) {
$CountryInput = $_POST['CountryInput'];
} else {
$CountryInput = '';
}
<form method="post" action="Screen2List.php">
<label for="CountryInput"><?php echo $arrMainPage[$MainPageCountry]["TextHeader"]; ?></label>
<select name="CountryInput" >
<option><?php echo $arrMainPage[$MainPageSelectOne]["TextHeader"]; ?></option>
<?php
$rcsCountry = $db->query($qryCountry);
while ($row = $rcsCountry->fetch_array(MYSQLI_BOTH)) {
if ($row["CountryCodePK"] == $CountryInput) {
$CountrySelected = "selected";
} else {
$CountrySelected = "";
}
?><Option <?php echo $CountrySelected; ?> value="<?php echo $row["CountryCodePK"]; ?>"><?php echo $row["CountryDescription"]; ?></option>
<?php
}
echo "</select>"
?>
</select>
<label for="CategoryInput"><?php echo $arrMainPage[$MainPageCategory]["TextHeader"]; ?></label>
<select name="CategoryInput" >
<option><?php echo $arrMainPage[$MainPageSelectOne]["TextHeader"]; ?></option>
<?php
$rcsCategory = $db->query($qryCategory);
while ($row = $rcsCategory->fetch_array(MYSQLI_BOTH)) {
if ($row["CategoryCodePK"] == $CategoryInput) {
$CategorySelected = "selected";
} else {
$CategorySelected = "";
}
?><Option <?php echo $CategorySelected; ?> value="<?php echo $row["CategoryCodePK"]; ?>"><?php echo $row["CategoryDescription"]; ?></option>
<?php
}
echo "</select>"
?>
</select>
.
.
.
<button type="submit" class="searchbutton" value="" /><img src="img/searchbutton.png"></button>
</form>
Cuando el usuario selecciona las distintas opciones q desea d los distintos filtros le da al botón de search y entonces se recarga la página con los valores $_POST['CountryInput'], $_POST['CategoryInput'], etc.
Estos filtros están en la parte izquierda del screen, y en el centro tengo los elementos mostrados en lista y tablas y paginados:
Código PHP:
Ver original<?php
$qryCInformation = str_replace(".StartPage.", $beginning, $qryCInformation); $qryCInformation = str_replace(".NumberOnPage.", $SetNumberOnPage, $qryCInformation);
$rcsNumberOnPage = $db->query($qryCInformation);
foreach($rcsNumberOnPage as $NumberOnPages => $row) {
?>
<div class="list">
<table id="boxcrwidth" >
<colgroup id="picturecrtable" />
<tr>
<td rowspan="7" colspan="2"><img src="<?php echo $row["SoucreUrlImage"]; ?>"></td>
<td class="titlestable" ><?php echo ($row["Category"]);?></td>
<td class="titlestable" ><?php echo $row["Initial_registration"];?></td>
<td class="titlestable" >...</td>
</tr>
<tr>
<td id="heighttexttable" rowspan="6" colspan="4" > <?php echo $row["Title"];?></td>
</tr>
<tbody></tbody>
</table>
</div>
<?php
}
?>
Con todo esto tengo todos los elementos mostrados por páginas en tablas y con sus correspondientes caracterísitcas, ahora quiero por ejemplo que cuando el usuario elija un país se muestren todos los elementos d ese país nada más, ya que ahora se muestran todos por defecto. La característica país no la enseño en la tabla porq no lo necesito pero la categoría si, quiero q aunq no se muestre por pantalla el país en las tablas, al seleccionar el país aparezcan solo los elementos d ese país y la categoría igual pero esta si que se muestra.
Para ello en el primer if que puse al principio en el código estoy metiendo una variable $DataFilter que usaré para compararlas con mi query:
Código PHP:
Ver original$DataFilter="";
if (isset ($_POST['CountryInput'])) { $CountryInput = $_POST['CountryInput'];
$DataFilter = "Previous_ownerCountry = '" +$CountryInput +"' ";
} else {
$CountryInput = '';
}
if (isset ($_POST['CategoryInput'])) { $CategoryInput = $_POST['CategoryInput'];
if($DataFilter!="") {
$DataFilter += " AND ";
}
$DataFilter += " = '" + $CategoryInput +"' ";
} else {
$CategoryInput = '';
}
Mi pregunta es, cómo uso esta variable para meterla en mi query o compararla d tal manera que me muestre por pantalla lo que quiero? Este es mi query:
Código MySQLI:
Ver original$qryCInformation = "SELECT C.SoucreUrlImage, C.Initial_registration, C.Title
FROM tbl_cr AS C
ORDER BY C.Initial_registration ASC
LIMIT .StartPage.,.NumberOnPage.";
Muchas gracias.