gpt4 book ai didi

php - 如何在php/html中逐个回显多个表数据

转载 作者:行者123 更新时间:2023-11-29 18:26:21 27 4
gpt4 key购买 nike

我有两个表,例如:

现在我想显示第一个表中的前 5 个,然后显示发送表中的前 5 个,然后再显示第一个表中的下一个 5-10 个,以及第二个表中的下一个 5-10 个,依此类推。

我有这种方式的代码,请建议我:-

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "songsind";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT sno, title, img, mp3 FROM ";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
echo "<table style='width:100%'>
<tr>
<th>S.No</th>
<th>Title of Song</th>
<th>Image</th>
<th>MP3</th>
</tr>";
while($row = $result->fetch_assoc()) {

echo "<tr><td> " . $row["sno"]. " </td><td> " . $row["title"]. "</td> <td><img src=' " . $row["img"]. " 'height='100' width='100'></img></td><td> <iframe src=' " . $row["mp3"]. " ' height = '100' width ='200' </iframe></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>

最佳答案

我没试过,但这可能有用。

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "songsind";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$tables = array("eros", "saregama", "sony", "tips");

foreach($tables as $tbl){
$sql = "SELECT sno, title, img, mp3 FROM $tbl limit 5";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
echo "<table style='width:100%'>
<tr>
<th>S.No</th>
<th>Title of Song</th>
<th>Image</th>
<th>MP3</th>
</tr>";
while($row = $result->fetch_assoc()) {

echo "<tr><td> " . $row["sno"]. " </td><td> " . $row["title"]. "</td> <td><img src=' " . $row["img"]. " 'height='100' width='100'></img></td><td> <iframe src=' " . $row["mp3"]. " ' height = '100' width ='200' </iframe></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
}
$conn->close();
?>

关于php - 如何在php/html中逐个回显多个表数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46157191/

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