[英]How to echo multiple table data one after the other in php/html
我有兩個表,如:
現在我想從發送表中的前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();
?>
您必須選擇表以從我的SQL中獲取數據
SELECT sno, title, img, mp3 FROM ";
注意此聲明
您的聲明不完整,您必須使用此語句:
SELECT sno, title, img, mp3 FROM (table name)";
我沒有嘗試過,但這可能有用。
<?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();
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.