此代码调用数据库中的数据:
$sql = "SELECT * FROM products WHERE productid=$productid;";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0){
while ($row = mysqli_fetch_assoc($result)){
echo "<b>Event name: </b>";
echo "";
echo $row['1_name'];
echo "<p></p> ";
echo "<b>Event Venue: </b>";
echo " ";
echo $row['1_price'];
echo " <p></p>";
echo "<b>Event Date: </b>";
echo " ";
echo $row['1_quantity'];
echo " <p></p>";
?>
SQL DATABASE:
1_name varchar(256),
1_price int(11),
1_quantity int(11),
2_name varchar(256),
2_price int(11),
2_quantity int(11),
3_name varchar(256),
3_price int(11),
3_quantity int(11),
4_name varchar(256),
4_price int(11),
4_quantity int(11),
5_name varchar(256),
5_price int(11),
5_quantity int(11),
6_name varchar(256),
6_price int(11),
6_quantity int(11),
7_name varchar(256),
7_price int(11),
7_quantity int(11)
);
答案 0 :(得分:0)
要查看所有产品数据,请从
更改您的查询 "SELECT * FROM products WHERE productid=$productid"
到
"SELECT * FROM products"
要根据用户的输入限制产品,请使用此查询
"SELECT * FROM products LIMIT $limit"
所述查询将获得第n个产品数量,具体取决于集合$limit
如果您想查看最新产品并仍设置限制,可以使用此查询
"SELECT * FROM products ORDER BY productid DESC LIMIT $limit"