[英]How to echo multiple table data one after the other in php/html
I have two tables Like: 我有两个表,如:
Now i want to display first 5 from first table after that first 5 from send table and again next 5-10 from first table and next 5-10 from second table on so on. 现在我想从发送表中的前5个显示第一个表中的前5个,再从第一个表中显示下一个5-10,再从第二个表中显示下一个5-10,依此类推。
I have code in this fashion aso please suggest me:- 我也有这种方式的代码,请建议我:-
<?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();
?>
You must select the table to fetch data from my sql 您必须选择表以从我的SQL中获取数据
SELECT sno, title, img, mp3 FROM ";
Notice this statment 注意此声明
Your statement not full and you must use this: 您的声明不完整,您必须使用此语句:
SELECT sno, title, img, mp3 FROM (table name)";
I haven't tried, but this might work. 我没有尝试过,但这可能有用。
<?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.