问题
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);
回答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.
来源:https://stackoverflow.com/questions/51598716/how-to-concatenate-html-stylized-table-with-php-and-sql