Paging with Switch

Asked

Viewed 243 times

-1

Where I choose my 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 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 trouble there because I can only see the first data entered.

  • I placed advice?

  • No, it’s C. But I always thought it was C’s'...

  • 3

    Ah, no . Municipalities are localities in Portugal.

  • @user3253195, please [Edit] and the question to include more information and description of the problem. As stated in the answer below, it is not clear what the problem is... The comment you made there should be included here in the question itself. (ah, yes, in Galicia and Asturias County is also used in that sense :)

1 answer

1

I think the question has become a little vague, since you haven’t given us much of your business rule on the flow level. However from what I could notice in a quick analysis of its code, when it makes use of the function LIMIT, in your SQL, you pass two variables as parameter.

To my understanding regarding your inquiry of the last line, concerning to be able to see only the first data entered, I imagine that it is only a small confusion with the values that the variables $inicio and $quantidade are assuming in their SQL command. A $quantidade is only a static store for the value 1, because I did not find in your code some time when its value is changed.

Therefore, every result of your queries just displayed one single record. Therefore, as a consequence of $quantidade be static, the $inicio boils down to $pagina - $quantidade, assuming your variable check GET is always returning 1, SQL execution would always bring the record 0.

  • I want him to show me all the data of the case ['Indifferent','Indifferent','Indifferent']: .. that I have been wrong to change?

  • Why are you using LIMIT?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.