我是一名PHP初学者,我希望以垂直方式显示所有结果。出于某种原因,当有多个结果时,它只是将每个结果放在另一个结果旁边而不是另一个结果。
任何帮助都将受到高度赞赏。
这是我的代码
include "conexiondb.php";
if (isset($_POST['search'])) { // Search is the "name" attribute in the HTML input. The ones used with the "$_POST"
$busca = mysqli_real_escape_string($con, ($_POST['search'])) ;
$criteria = mysqli_real_escape_string($con, ($_POST['criteria'])) ;
if ($busca!="") {
$busqueda=$con->query("SELECT * FROM members WHERE {$criteria} = '{$busca}' ");
if ($busqueda === false) {
die('Could not connect:'.mysql_error()); // TODO: better error handling
}
}
echo "<div id ='tablennvoltura'><table border='1'>
<tr>
<th>Name</th>
<th>Address</th>
<th>Town</th>
<th>Zip</th>
<th>Cellphone</th>
<th>Birthday</th>
<th>Email</th>
<th>id</th>
<th>Editar</th>
<th>Nueva orden</th>
<th>Ver Ordenes</th>
</tr>";
while ($muestra=$busqueda->fetch_array()) {
echo '<td>'.$muestra['name'].' </td>';
echo '<td>' .$muestra['address']. '</td>';
echo '<td>' .$muestra['town']. '</td>';
echo '<td>' .$muestra['zip']. '</td>';
echo '<td>' .$muestra['cellphone']. '</td>';
echo '<td>' .$muestra['birthday']. '</td>';
echo '<td>' .$muestra['email']. '</td>';
echo '<td>' .$muestra['id']. '</td>';
echo "<td>"."<a href=\"memberdisplay.php?id=".$muestra['id']."\">See member</a>"." </td>";
echo "<td>"."<a href=\"formproducto2.php?cedula=".$muestra['id']."\">Nueva Orden</a>"."</td>";
echo "<td>"."<a href=\"ordenes.php?cedula=".$muestra['id']."\">Ordenes</a>"."</td>";
}
echo "</table></div>";
}
echo "</form>";
答案 0 :(得分:2)
因为您将每个变量放入表格单元格中,但单元格未封装成一行(<tr>... </tr>
)。
while ($muestra=$busqueda->fetch_array()) {
echo '<tr>';
...
echo '</tr>';
}
实际上,这个问题与php没什么关系,这纯粹是一个HTML问题。