Show php data inside tabs

Asked

Viewed 369 times

-1

I have a question about tabs. Previously had the data to be shown all within a table with pagination .

Now my doubt is. with tabs divisions I have to open and close php every time I change tab? How I can make tabs?

It used to be like this:

include("conectar.php");

$quantidade = 1;
$pagina = (isset($_GET ['pagina'])) ? (int)$_GET['pagina'] : 1;
$inicio = ($quantidade * $pagina) - $quantidade;
$sql = "select * from Tables order by tb_trabalhador.id asc LIMIT $inicio,   $quantidade"  ;
    $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>";

    echo  "<tr><td>Morada:</td>"; echo "<td>";
    if ($exibe['Morada']){ echo $exibe['Morada'];}else{echo 'N/D';} echo "</td></tr>";

     echo  "<tr><td>Distrito:</td>"; echo "<td>";
     if ($exibe['Distrito']){ echo $exibe['Distrito'];}else{echo 'N/D';} echo "</td></tr>";

     echo  "<tr><td>Concelho:</td>"; echo "<td>";
     if ($exibe['Concelho']){ echo $exibe['Concelho'];}else{echo 'N/D';} echo "</td></tr>";

Now I’ve got it so it’s not filled:

  <div id="tabs-1">
    <p>Content for Tab 1</p>
</div>
<div id="tabs-2">
    <p>Content for Tab 2</p>
</div>
<div id="tabs-3">
    <p>Content for Tab 3</p>
</div>

  • Como consigo fazer a paginação com as tabs didn’t I understand? could explain better?

  • In the first example it was as had to show the Mysql data in table form and before the table had the pagination. But I decided to improve this way and I want the mysql data to appear in different places in an organized way. By changing this I didn’t know where to put the paging to work

2 answers

1

Your PHPshould look like this:

$i = 1;
while($exibe = mysql_fetch_array($qr)){
echo"
<div id='tabs-".$i."'>
    <p>".$exibe['Morada']."</p>
    <p>".$exibe['Distrito']."</p>
    <p>".$exibe['Concelho']."</p>
</div>
";
$i++;
}

The variable $i is making the count for the CSS that you are applying, to each WHILE that returns for verification, he adds +1, so when finalize the information it will put each CSS in its place. If you have to upload a lot of information inside the TABS, will have to be made a ECHO for each TABS.

  • 1

    A doubt. The example you left is only for a correct tab? And before $i have to open php

0

Hello. The best pagination option is with data set $inicio and $limite making just one query of desirable data SELECT lista FROM tablet LIMIT $inicio,$limite. And yet you win with execution performance.

An example:

http://daltonmenezes.wordpress.com/2010/06/17/paginacao-de-resultados-com-php-e-mysql-aprenda-definitivamente-no-passo-a-passo/


I think this is it:

<?php
include("conectar.php");

$quantidade = 1;
$pagina = (isset($_GET ['pagina'])) ? (int)$_GET['pagina'] : 1;
$inicio = ($quantidade * $pagina) - $quantidade;
$sql = "select * from Tables order by tb_trabalhador.id asc LIMIT $inicio,   $quantidade"  ;
    $qr = mysql_query($sql) or die(mysql_error());
    while($exibe = mysql_fetch_array($qr)){

    //verificação sequencial. 
    if (!empty($exibe['Morada'])){ 
      $morada = 'N/D';
    }else{
      $morada = $exibe['Morada']
    }
    if (!empty($exibe['Distrito'])){ 
      $distrito = 'N/D';
    }else{
      $distrito = $exibe['Distrito']
    }
    if (!empty($exibe['Concelho'])){ 
      $conselho = 'N/D';
    }else{
      $conselho = $exibe['Concelho']
    }

    echo'<div id="tabs-1">
           <p>Nome: '.$exibe["Nome"].'</p>
           <p>Morada:   '.$morada.'</p>
           <p>Distrito: '.$distrito.'</p>
           <p>Concelho: '.$conselho.'</p>
         </div>';
 }
?>   
  • Thanks, but my problem isn’t paging because I already did. But I changed the way to show the data and put tabs and here is my problem.

  • Inside the div I have to open the correct php?

Browser other questions tagged

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