gpt4 book ai didi

彼此之间的php表格行

转载 作者:行者123 更新时间:2023-11-28 23:20:46 25 4
gpt4 key购买 nike

我有一个表和来自 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>&nbsp";
$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();

}

最佳答案

您需要在第二个表中创建一个“albumid”,这样您就可以用正确的专辑打印正确的艺术家。

然后修改代码如下:

$sql = mysqli_query($db,"SELECT * FROM albums");  //get the albums

if($sql) {
if(mysqli_num_rows($sql)>0) { //if you have some albums to print...
while ($row = mysqli_fetch_assoc($sql)) {

//start printing a row
$h.= "<tr>";
$h.= "<td>".$row['id']."</td>";
$h.= "<td>".$row['albumName']."</td>";

//now get the artiest for the album by querying the correct albumid
$albumid = $row['id'];
$sql1 = mysqli_query($db,"SELECT * FROM artiesten where albumid = '$albumid' ");

while ($row1 = mysqli_fetch_assoc($sql1)){

$h.= "<td>".$row1['artiest']."</td>"; //print the right artiest
}

$h.= "<td style='text-align:right;'><a href='/?action=show-song&id=".$row['id']."'' class='btn btn-primary'>Zie nummers</a>&nbsp";
$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>";

}

关于彼此之间的php表格行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41694603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com