1

So, i have this code that returns me a simple table with the correct db values:

<?php
    echo "<table border='1'>
          <tr>
            <th>Código</th>
            <th>Nome</th>
            <th>Indicou</th>
          </tr>";

    while($coluna_bd_tabela = mysqli_fetch_array($sql_indicador_resul)){
        echo "<tr>";
        echo "<td>" . $coluna_bd_tabela['usu_codigo'] . "</td>";
        echo "<td>" . $coluna_bd_tabela['usu_nome'] . "</td>";
        echo "<td>" . $coluna_bd_tabela['usu_indicador_codigo'] . "</td>";
        echo "</tr>";
    }

    echo "</table>";
?>

And this one is the stylized table without the querys working:

<table class="table table-striped projects">
  <thead>
    <tr>
      <th style="width: 1%">#</th>
      <th style="width: 20%">Nome</th>
      <th>Membros Recentes</th>
      <th>Project Progress</th>
      <th>Status</th>
      <th style="width: 20%">#Edit</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>echo $coluna_bd_tabela['usu_codigo']</td>
      <td>
        <a> echo $coluna_bd_tabela['usu_nome']</a>
        <br />
        <small>echo $coluna_bd_tabela['usu_indicou']</small>
      </td>
      <td>
        <ul class="list-inline">
          <li>
            <img src="images/user.png" class="avatar" alt="Avatar">
          </li>
          <li>
            <img src="images/user.png" class="avatar" alt="Avatar">
          </li>
          <li>
            <img src="images/user.png" class="avatar" alt="Avatar">
          </li>
          <li>
            <img src="images/user.png" class="avatar" alt="Avatar">
          </li>
        </ul>
      </td>
      <td class="project_progress">
        <div class="progress progress_sm">
          <div class="progress-bar bg-green" role="progressbar" data-transitiongoal="57"></div>
        </div>
        <small>57% Complete</small>
      </td>
      <td>
        <button type="button" class="btn btn-success btn-xs">Success</button>
      </td>
      <td>
        <a href="#" class="btn btn-primary btn-xs"><i class="fa fa-folder"></i> View </a>
        <a href="#" class="btn btn-info btn-xs"><i class="fa fa-pencil"></i> Edit </a>
        <a href="#" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i> Delete </a>
      </td>
    </tr>
  </tbody>

I want to show the stylized table with the values of the querys, but this is destroying me. The database connection is fine, these are the querys on a include connection, they are working fine too, as have been shown on the simple table:

$sql_indicador = "SELECT * FROM esc_usuarios WHERE usu_indicador_codigo = '" . $_SESSION['codigo'] . "'";
$sql_indicador_resul = mysqli_query($conexao, $sql_indicador);
confetti
  • 1,062
  • 2
  • 12
  • 27
  • 1
    If I'm not wrong, you're missing opening `` PHP tags for `echo` statements. – rmalviya Jul 30 '18 at 16:47
  • ^ that too. I'm actually confused what you say is actually working as you like, and which is not working. It may be all you need is those open/close php tags... then just wrap inside your `tbody` with the `while`. – IncredibleHat Jul 30 '18 at 16:50
  • Ignore me if I'm wrong, but can't $_SESSION variables be altered using some browser add-ons? In that case, I advise you to escape the session variable you're using in your MySQL query. – confetti Jul 30 '18 at 16:52
  • yeah, I know, but yet it is gonna show only one user from many, i want to generate as many as exists on the database –  Jul 30 '18 at 16:52

1 Answers1

1

To provide a full solution:

<table class="table table-striped projects">
    <thead>
        <tr>
            <th style="width: 1%">#</th>
            <th style="width: 20%">Nome</th>
            <th>Membros Recentes</th>
            <th>Project Progress</th>
            <th>Status</th>
            <th style="width: 20%">#Edit</th>
        </tr>
    </thead>

    <?php while($coluna_bd_tabela = mysqli_fetch_array($sql_indicador_resul)){ ?>
            <tbody>
                <tr>
                    <td><?php echo $coluna_bd_tabela['usu_codigo']; ?></td>
                    <td>
                        <a><?php echo $coluna_bd_tabela['usu_nome']; ?></a>
                        <br />
                        <small><?php echo $coluna_bd_tabela['usu_indicou']; ?></small>
                    </td>
                    <td>
                        <ul class="list-inline">
                            <li>
                                <img src="images/user.png" class="avatar" alt="Avatar">
                            </li>
                            <li>
                                <img src="images/user.png" class="avatar" alt="Avatar">
                            </li>
                            <li>
                                <img src="images/user.png" class="avatar" alt="Avatar">
                            </li>
                            <li>
                                <img src="images/user.png" class="avatar" alt="Avatar">
                            </li>
                        </ul>
                    </td>
                    <td class="project_progress">
                        <div class="progress progress_sm">
                            <div class="progress-bar bg-green" role="progressbar" data-transitiongoal="57"></div>
                        </div>
                        <small>57% Complete</small>
                    </td>
                    <td>
                        <button type="button" class="btn btn-success btn-xs">Success</button>
                    </td>
                    <td>
                        <a href="#" class="btn btn-primary btn-xs"><i class="fa fa-folder"></i> View </a>
                        <a href="#" class="btn btn-info btn-xs"><i class="fa fa-pencil"></i> Edit </a>
                        <a href="#" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i> Delete </a>
                    </td>
                </tr>
            </tbody>
    <?php } ?>
</table>

You forgot to use the <?php and ?> opening and closing tags around the echo statements. Furthermore, you missed the ; at the end of each statement. I've also moved the beginning and the end of the table out of PHP's echo since I believe it looks much clearer this way.

confetti
  • 1,062
  • 2
  • 12
  • 27
  • 1
    Edit has been made. Personally, I would suggest moving the `` out of it too. If it's always just one row in the databse, I would suggest getting rid of the whileloop entirely and simply using `$coluna_bd_tabela = mysqli_fetch_array($sql_indicador_result);`. – confetti Jul 30 '18 at 16:58
  • 2
    You could argue that `` should be outside the while... but in html spec, it is perfectly ok to have multiple `` in a single ``. So it works out either way. One could even add a unique `id="block_x"` to those for easier javascript manipulation.
    – IncredibleHat Jul 30 '18 at 16:58
  • Thanks for the suggestions, i removed the –  Jul 30 '18 at 17:21
  • @confetti did the job, i made some changes and it did work perfectly, awesome! –  Jul 30 '18 at 17:22