Tabs with different Query's PHP

-2

I'm having trouble creating a page with two tabs but each with a different query.

    <ul>
    <li><a href="#tabs-1">TAB1</a></li>
<li><a href="#tabs-2">TAB2</a></li>
    </ul>
    <?php

      include("conectar.php");

echo'<div id="tabs-1">
$sql = "select * from Tabelas
where Campo1 and campo2"';
echo'   $qr = mysql_query($sql) or die(mysql_error())';
echo'   while($exibe = mysql_fetch_array($qr)){

     <li class="ui-widget-content"><h3><a href="NaoautorizadoMostrar.php?id='.$exibe['id'].'">'.$exibe['Nome'].'</h3></a></li>;
  } </div>';


    echo'<div id="tabs-2">
$sql = "select * from Tabelas
where Campo3 and campo4"';
echo'   $qr = mysql_query($sql) or die(mysql_error())';
echo'   while($exibe = mysql_fetch_array($qr)){

     <li class="ui-widget-content"><h3><a href="NaoautorizadoMostrar.php?id='.$exibe['id'].'">'.$exibe['Nome'].'</h3></a></li>;
  } </div>';

error:

  

Notice: Undefined variable: displays in.

Thank you

    
asked by anonymous 27.05.2014 / 15:38

2 answers

1

It's not clear what content you want to display on the tab. It would also be interesting to let you know which javascript library you are using to create the tabs.

Try to be a bit more organized, this will make it easier to identify errors and maintain your code.

  • Avoid using echo to generate HTML content, this makes it difficult to read the code.
  • Also avoid inserting queries in the middle of your HTML code, try to centralize queries at the beginning of the script or preferably adopt a MVC framework .
  • From the HTML viewpoint, your code is wrong. It has LIs without OL / UL country.
  • As the HTML of each tab is the same, you can put the contents of each tab in an array and generate the different tabs through a foreach, without having to repeat code.
  • Here is my organization suggestion:

    <?php
    include("conectar.php"); 
    
    // Dados da tab1
    $sql = "select * from Tabelas where Campo1 and campo2";
    $rs1 = mysql_query($sql) or die(mysql_error());
    
    // Dados da tab2
    $sql = "select * from Tabelas where Campo3 and campo4";
    $rs2 = mysql_query($sql) or die(mysql_error());
    
    // Tabs
    $tabs = array($rs1, $rs2);     
    ?>
    <html>
    ...
       <!-- Geração do HTML dos links para as tabs -->
       <ul>   
            <?php $c = 1;?>
            <?php foreach($tabs as $rs):?>
                <li><a href="#tab-<?php echo $c;?>">Aba <?php echo $c; ?></a></li>
            <?php endforeach; ?>
       </ul>
    
       <!-- Geração do HTML do CONTEUDO das tabs -->
       <?php $c = 1;?>
       <?php foreach($tabs as $rs):?>
          <div id="tabs-<?php echo $c++;?>">
              <!-- Conteúdo da aba. -->
              <?php while($row=mysql_fetch_array($rs)): ?>                    
                  <?php echo $row['Nome'];?>
              <?php endwhile;?>
          </div>
       <?php endforeach; ?>
    ...
    </html>
    
        
    28.05.2014 / 01:11
    -1

    Your code is unstructured, I think it solves your problem:

    <?php
    
          include("conectar.php");
    
    echo '<div id="tabs-1">';
    $sql = "select * from Tabelas where Campo1 and campo2";
    $qr = mysql_query($sql) or die(mysql_error());
    while($exibe = mysql_fetch_array($qr)){
    
        echo '<li class="ui-widget-content"><h3><a href="NaoautorizadoMostrar.php?id='.$exibe['id'].'">'.$exibe['Nome'].'</h3></a></li>';
      }
     echo '</div>';
    
    
       echo'<div id="tabs-2">';
     $sql = "select * from Tabelas where Campo3 and campo4";
     $qr = mysql_query($sql) or die(mysql_error());
     while($exibe = mysql_fetch_array($qr)){
    
        echo '<li class="ui-widget-content"><h3><a href="NaoautorizadoMostrar.php?id='.$exibe['id'].'">'.$exibe['Nome'].'</h3></a></li>';
      } 
    
      echo '</div>';
    
        
    27.05.2014 / 15:47