Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/07/2013, 07:23
Novato2013
 
Fecha de Ingreso: junio-2013
Ubicación: Madrid
Mensajes: 61
Antigüedad: 11 años, 8 meses
Puntos: 5
Filtro=PHP+mysquli

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 original
  1. if (isset ($_POST['CountryInput'])) {
  2.     $CountryInput = $_POST['CountryInput'];
  3. } else {
  4.     $CountryInput = '';
  5. }
  6.  
  7. <form method="post" action="Screen2List.php">
  8.            <label for="CountryInput"><?php echo $arrMainPage[$MainPageCountry]["TextHeader"]; ?></label>
  9.                                     <select name="CountryInput" >
  10.                                         <option><?php echo $arrMainPage[$MainPageSelectOne]["TextHeader"]; ?></option>
  11.                                         <?php
  12.                                         $rcsCountry = $db->query($qryCountry);
  13.                  
  14.                                         while ($row = $rcsCountry->fetch_array(MYSQLI_BOTH)) {
  15.                                            
  16.                                             if ($row["CountryCodePK"] == $CountryInput) {
  17.                                                 $CountrySelected = "selected";
  18.                                             } else {
  19.                                                 $CountrySelected = "";
  20.                                             }
  21.                                            
  22.                                             ?><Option <?php echo $CountrySelected; ?> value="<?php echo $row["CountryCodePK"]; ?>"><?php echo $row["CountryDescription"]; ?></option>
  23.                                         <?php
  24.                                         }
  25.                                            
  26.                                         echo "</select>"
  27.                                         ?>
  28.                                     </select>
  29. <label for="CategoryInput"><?php echo $arrMainPage[$MainPageCategory]["TextHeader"]; ?></label>
  30.                                     <select name="CategoryInput" >
  31.                                         <option><?php echo $arrMainPage[$MainPageSelectOne]["TextHeader"]; ?></option>
  32.                                         <?php
  33.                                         $rcsCategory = $db->query($qryCategory);
  34.        
  35.                                         while ($row = $rcsCategory->fetch_array(MYSQLI_BOTH)) {
  36.                                            
  37.                                             if ($row["CategoryCodePK"] == $CategoryInput) {
  38.                                                 $CategorySelected = "selected";
  39.                                             } else {
  40.                                                 $CategorySelected = "";
  41.                                             }
  42.                                            
  43.                                             ?><Option <?php echo $CategorySelected; ?> value="<?php echo $row["CategoryCodePK"]; ?>"><?php echo $row["CategoryDescription"]; ?></option>
  44.                                         <?php
  45.                                         }
  46.                                        
  47.                                         echo "</select>"
  48.                                         ?>                     
  49.                                     </select>
  50. .
  51. .
  52. .
  53. <button type="submit" class="searchbutton" value="" /><img src="img/searchbutton.png"></button>
  54. </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
  1. <?php
  2.                 $qryCInformation = str_replace(".StartPage.", $beginning, $qryCInformation);
  3.                 $qryCInformation = str_replace(".NumberOnPage.", $SetNumberOnPage, $qryCInformation);
  4.                
  5.                 $rcsNumberOnPage = $db->query($qryCInformation);
  6.  
  7.                 foreach($rcsNumberOnPage as $NumberOnPages => $row) {
  8.                 ?>
  9.                     <div class="list">
  10.                         <table id="boxcrwidth" >
  11.                             <colgroup id="picturecrtable" />
  12.                             <tr>
  13.                                 <td rowspan="7" colspan="2"><img src="<?php echo $row["SoucreUrlImage"]; ?>"></td>
  14.                                 <td class="titlestable" ><?php echo ($row["Category"]);?></td>
  15.                                 <td class="titlestable" ><?php echo $row["Initial_registration"];?></td>
  16.                                 <td class="titlestable" >...</td>
  17.                             </tr>
  18.                             <tr>
  19.                                 <td id="heighttexttable" rowspan="6" colspan="4" > <?php echo $row["Title"];?></td>
  20.                             </tr>
  21.                             <tbody></tbody>
  22.                         </table>
  23.                     </div>
  24.                 <?php
  25.                 }
  26.                 ?>
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
  1. $DataFilter="";
  2.  
  3. if (isset ($_POST['CountryInput'])) {
  4.     $CountryInput = $_POST['CountryInput'];
  5.     $DataFilter = "Previous_ownerCountry = '" +$CountryInput +"' ";
  6. } else {
  7.     $CountryInput = '';
  8. }
  9.  
  10. if (isset ($_POST['CategoryInput'])) {
  11.     $CategoryInput = $_POST['CategoryInput'];
  12.    
  13.     if($DataFilter!="") {
  14.         $DataFilter += " AND ";
  15.     }
  16.    
  17.     $DataFilter += "   = '" + $CategoryInput +"' ";
  18. } else {
  19.     $CategoryInput = '';
  20. }

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
  1. $qryCInformation = "SELECT C.SoucreUrlImage, C.Initial_registration, C.Title
  2.                       FROM tbl_cr AS C
  3.                       ORDER BY C.Initial_registration ASC
  4.                       LIMIT .StartPage.,.NumberOnPage.";

Muchas gracias.