【问题标题】:How to return the results of my query in rows如何按行返回我的查询结果
【发布时间】:2017-05-24 16:50:53
【问题描述】:

这是我的查询,它工作正常,但我如何在 HTML TABLE 中返回结果。例如,我想要第 1 行的前 5 个结果,第 2 行的下 5 个结果,依此类推。任何帮助都会很棒。谢谢!

<?php
$servername = "XXX";
$username = "XXX";
$password = "XXX";
$dbname = "XXX";

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

$sql = "SELECT * FROM manufacturer LIMIT 10 OFFSET 0";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo  '<td><a href="index.php?route=product/manufacturer/info& 
manufacturer_id='. $row["manufacturer_id"] .'"><img src="image/' .  
$row["image"] .'"></a></td>';
}
} else {
echo "0 results";
}
$conn->close();

【问题讨论】:

标签: php html html-table


【解决方案1】:
<?php
$servername = "XXX";
$username = "XXX";
$password = "XXX";
$dbname = "XXX";

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

$sql = "SELECT * FROM manufacturer LIMIT 10  OFFSET 0";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
$i=0;
while($row = $result->fetch_assoc()) {
If($i==5){
echo "</tr>";
echo "<tr>";
$i=0;
}
echo  '<td><a href="index.php? route=product/manufacturer/info& 
manufacturer_id='. $row["manufacturer_id"] .'">.   <img src="image/' .  
$row["image"] .'"></a></td>';
$i++;
}
} else {
echo "0 results";
}
$conn->close();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-16
    • 2013-10-01
    • 2016-03-07
    • 2017-12-05
    • 2012-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多