我有两个表,如:
现在我想要显示第一个表中的前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();
?>发布于 2017-09-11 21:57:45
我还没试过,但这可能行得通。
<?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();
?>https://stackoverflow.com/questions/46157191
复制相似问题