Switch Paging [duplicate]

-1

Where do I choose the options:

  <span class="IWLABEL10CSS" id="IWLABEL7">Distrito</span>
  <select name="Distrito" size="1" width="180" class="COMBODISTCSS" id="COMBOFAB" tabindex="1">
 <option value="Indiferente">Indiferente</option>
 <option value="Aveiro">Aveiro</option>   
    </select>
    <span class="IWLABEL11CSS" id="IWLABEL7">Concelho</span>
   <select name="Concelho" size="1" width="195" class="COMBOCONCCSS" id="COMBOCID" tabindex="1">
  <option data-Distrito="Indiferente" value="Indiferente">Indiferente</option>

<option data-Distrito="Aveiro" value="Indiferente">Indiferente</option>
     <option data-distrito="Aveiro" value="Agueda">Agueda</option>
 </select>

 <span class="IWLABEL4CSS" id="IWLABEL4">Estado</span>
  <select name="estado" size="1" width="195" class="COMBOFABCSS" id="COMBOFAB" tabindex="1">
 <option value="Indiferente">Indiferente</option>
<option value="Autorizado">Autorizado</option>
<option value="Condicionado">Condicionado</option>
<option value="Nao Autorizado">Não Autorizado</option>

Where do I do the query:     

include("conectar.php");

$quantidade = 1;
$pagina = (isset($_GET ['pagina'])) ? (int)$_GET['pagina'] : 1;

$inicio = ($quantidade * $pagina) - $quantidade;

$sql ="";
if (isset($_POST['estado']) AND ($_POST['Distrito']) AND ($_POST['Concelho']))
{
    switch([$_POST['estado'] , $_POST['Distrito'], $_POST['Concelho']])
    {
    case ['Indiferente','Indiferente','Indiferente']:
        $sql = "select * from tb_detalhe_trabalhador inner join tb_trabalhador on   tb_detalhe_trabalhador.id = tb_trabalhador.id inner join tb_equipamentos on tb_detalhe_trabalhador.id = tb_equipamentos.id ORDER BY tb_trabalhador.id asc LIMIT $inicio,     $quantidade";
        $qr = mysql_query($sql) or die(mysql_error());
        break;

    case ['Indiferente','Aveiro','Indiferete']:
        $sql = "select * from tb_detalhe_trabalhador inner join tb_trabalhador on tb_detalhe_trabalhador.id = tb_trabalhador.id inner join tb_equipamentos on tb_detalhe_trabalhador.id = tb_equipamentos.id Where tb_trabalhador.Distrito = 'Aveiro' or 'AVEIRO' or 'aveiro' ORDER BY tb_trabalhador.id asc LIMIT $inicio, $quantidade";
        $qr = mysql_query($sql) or die(mysql_error());
        break;
    }
}

$qr = mysql_query($sql) or die(mysql_error());

while($exibe = mysql_fetch_array($qr)){
    echo "<table>"; 
    echo  "<tr><td>Nome:</td>";
    echo "<td>".$exibe["Nome"]."</td></tr>";
} 

$sqltotal = "SELECT id FROM tb_trabalhador";
$qrtotal = mysql_query($sqltotal) or die(mysql_error());
$numtotal = mysql_num_rows($qrtotal);
$totalpagina = ceil ($numtotal/$quantidade);

echo '<a href="?pagina=1">Primeira página</a>';

for ($i = 1; $i <= $totalpagina; $i++){
    if($i == $pagina)
        echo $i;
    else
        echo"<a href=\"?pagina=$i\">$i</a>";
}

echo '<a href="?pagina=$totalpagina">Ultima Pagina</a>';

?>  

I'm having difficulty there because I can only see the first data entered.

    
asked by anonymous 07.04.2014 / 11:25

1 answer

1

I think the question is a little vague, since it did not give us much of its flow-level business rule. But from what I can see in a quick analysis of your code, when you use the LIMIT function in your SQL, you pass two variables as a parameter.

As far as my understanding of your last line inquiry is concerned with seeing only the first data entered, I suppose it's just a little confusion with the values that $inicio and $quantidade are assuming at your command SQL. The $quantidade is just a static store for the 1 value, as I did not find any code in its code that changes its value.

So every result of your queries will only display one single record. Therefore, as a consequence of $quantidade being static, $inicio is summed to $pagina - $quantidade , assuming that its GET check is always returning 1 , SQL execution always returns 0 .

    
07.04.2014 / 16:37