view_products()下面仅显示我的表中的一项数据,product该表包含 20 条数据。取决于您放置在显示第一个数据的return $output;内部或显示最后一个数据的外部的位置。while loopwhile loop
<?php echo view_products(); ?>
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "password@edadmin";
$dbname = "estore";
$dbconn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
//Test if connection occurred,
if (mysqli_connect_errno()) {
die("Database connection failed: " .
mysqli_connect_error() .
" (" . mysqli_connect_errno() . ")");
}
function view_products()
{
global $dbconn;
$sql = "SELECT * FROM product";
$result = mysqli_query($dbconn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($products = mysqli_fetch_assoc($result)) {
$output = "<div class=\"col-lg-4 col-md-6 portfolio-item filter-app wow fadeInUp\">";
$output .= "<div class=\"portfolio-wrap\"><figure>";
$output .= "<img src=" . $products['ProductImage'] . " class=\"img-fluid\" alt=\"\">";
$output .= "<a href=" . $products['ProductImage'] . " data-lightbox=\"portfolio\" data-title=\"App 1\" class=\"link-preview\" title=\"Preview\"><i class=\"ion ion-eye\"></i></a>";
$output .= "</figure>";
$output .= " <div class=\"portfolio-info\">";
$output .= "<p><a href=\"#\">" . $products['ProductName'] . " </a></p>";
$output .= "<p>" . "₦ " . $products['ProductAmount'] . "</p>";
$output .= "</div></div></div>";
return $output;
}
} else {
return "No product yet";
} // return $output;
}
呼如林