作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个表,例如:
现在我想显示第一个表中的前 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/
我尝试在 d3.js 中进行链式转换。为此,我在数组中定义了一组转换,并(尝试)创建一个函数以使用 .each("end", function()) 递归调用它们,以在前一个为完成,但我还没有结果。
我是一名优秀的程序员,十分优秀!