PHP在html表中的结果限制为3行
我试图让我的搜索结果显示在表中的页面上,每行显示3个结果。我尝试了各种各样的方法,改变了很多次剧本,但最终还是绕圈子,回到了我原来的剧本 最终,我想将输出限制为每页50个,每行5个,但让它正确显示才是最重要的 任何帮助都会很棒 代码如下:PHP在html表中的结果限制为3行,php,html-table,Php,Html Table,我试图让我的搜索结果显示在表中的页面上,每行显示3个结果。我尝试了各种各样的方法,改变了很多次剧本,但最终还是绕圈子,回到了我原来的剧本 最终,我想将输出限制为每页50个,每行5个,但让它正确显示才是最重要的 任何帮助都会很棒 代码如下: <?php error_reporting(E_ALL); ini_set('display_errors', 1); function searchmembers($search_term){ global $con; $sq
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
function searchmembers($search_term){
global $con;
$sql = mysqli_query($con, "SELECT * FROM `artist` WHERE `Band` LIKE '%$search_term%' OR `Genre` LIKE '%$search_term%' LIMIT 0, 30 ") or die (mysqli_error());
$num_of_row = mysqli_num_rows($sql);
if ($num_of_row > 0 ){
while($row = mysqli_fetch_array($sql))
{
$id = $row['Band'];
$Pic = $row['Pic'];
?>
<?php
echo"<table>";?>
<td><img src="<?php echo $row['Pic']; ?>" height="100" width="100" align="middle" /></td>
<?php
echo "<td><a href ='profile.php?Band=$id' style='color:white; text-decoration:none;'>". $row['Band']."";
echo"</table>";
}
}
else
{
echo "<font color='red' size='4' >No result found!</font>";
}
}
?>
就快到了,只需要将3排水平放置
您想要分页吗?最终,我只想让它正确地显示出来。您在每一个while周期中都要创建一个表,但这是错误的。必须在“while”之前打开标记,并在其之后关闭“”。如果($i%3==1)改为if($i%3==0)如果($i%3==0)谢谢你,只需要把它们水平排列成3行就行了。经过一点修改,我已经解决了这个问题,最后一个if($i%3==1){?>控制每行的结果,第一行控制表中允许的数量,因此我现在将此设置为,并且它似乎显示正确。非常感谢您保持我的理智。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
function searchmembers($search_term){
global $con;
$sql = mysqli_query($con, "SELECT * FROM `artist` WHERE `Band` LIKE '%$search_term%' OR `Genre` LIKE '%$search_term%' LIMIT 0, 30 ") or die (mysqli_error());
$num_of_row = mysqli_num_rows($sql);
if ($num_of_row > 0 ){
$i=0;
echo"<table>";
while($row = mysqli_fetch_array($sql))
{
$id = $row['Band'];
$Pic = $row['Pic'];
$i++;
?>
<?php if($i%3==1){ ?>
<tr>
<?php }?>
<td><img src="<?php echo $row['Pic']; ?>" height="100" width="100" align="middle" /></td>
<?php
echo "<td><a href ='profile.php?Band=$id' style='color:white; text-decoration:none;'>". $row['Band']."";
<?php if($i%3==1){ ?>
</tr>
<?php }?>
}
echo"</table>";
}
else
{
echo "<font color='red' size='4' >No result found!</font>";
}