【发布时间】:2017-06-01 08:48:03
【问题描述】:
我有一张表和 MySql 的结果。第一行和第二行是相互的,但第三行不是。
代码:
$db = mysqli_connect($host, $user, $pass,$database);
if($db){
$h.= "";
$h.= "<form><table class='table table-striped table-hover'>";
$h.= "<tr>";
$h.= "<th>Nr.</th>";
$h.= "<th>Albums</th>";
$h.= "<th>Artiest</th>";
$h.= "<th>Nummer</th>";
$h.= "<th></th>";
$h.='<ul class="nav nav-pills" role="tablist">';
$h.=" <li role='presentation' class='active'><a href='http://localhost:8888/?action=album '>Albums<span class='badge'></span></a></li>";
$h.=' <li role="presentation"><a href="http://localhost:8888/?action=songs">Songs</a></li>';
//$h.='<input type="button" class="btn btn-primary style="float: right"><a href="http://localhost:8888/?action=add-album">';
$h.= "<td style='text-align:right;'><a href='/?action=add-album' class='btn btn-primary'>VOEG TOE</a></td>";
$h.='</ul>';
$h.="<br>";
$h.= "</tr>";
$sql = mysqli_query($db,"SELECT * FROM albums");
$sql1 = mysqli_query($db,"SELECT * FROM artiesten");
if($sql){
if(mysqli_num_rows($sql)>0){
while ($row = mysqli_fetch_assoc($sql)){
$h.= "<tr>";
$h.= "<td>".$row['id']."</td>";
$h.= "<td>".$row['albumName']."</td>";
while ($row1 = mysqli_fetch_assoc($sql1)){
$h.= "<td>".$row1['artiest']."</td>";
}
$h.= "<td>";
$h.= "<td style='text-align:right;'><a href='/?action=show-song&id=".$row['id']."'' class='btn btn-primary'>Zie nummers</a> ";
$h.= "<style='text-align:right;'><a href='/?action=delete-album&id=".$row['id']."'' class='btn btn-danger'>VERWIJDER</a></td>";
$h.= "</tr>";
}
}else{
echo "<tr>No Recore Found</tr>";
}
$h.= "</table></form>";
echo $htop;
echo $h;
echo $hbot;
}else{
echo "Query error".mysqli_error($db);
}
}else{
echo "connection error".mysqli_connect_error();
}
【问题讨论】:
-
你的问题是什么?
-
第三个结果"$h.="
".$row['albumName']." ";"怎么没有低于:"$h.= "".$row1['artiest']." "; " -
对不起,我的意思是“ $h.= "
".$row1['artiest']." ";"在“专辑名称”下方 -
@cashbee 结果“最艺术”正在彼此相邻,我希望它们彼此之间。图片:gyazo.com/768b313a498151323c22efeeac73f752
-
@johnsmith 因为它有自己的
while循环,然后它会在彼此之后创建一行,而不是像在一个循环中的其他人一样!当您在一个部分中循环遍历它时,您实际上会给出它自己的行。 另外,您可以编辑您的问题,而不是将其放入 cmets。
标签: php mysql html-table row