gpt4 book ai didi

php - 初学者 : php and mysql table issue

转载 作者:行者123 更新时间:2023-11-29 07:57:06 24 4
gpt4 key购买 nike

对 php 和 mysql 非常陌生,因此非常感谢所有帮助。我尝试搜索论坛,但不完全确定我需要搜索什么。我有一个表单要求用户选择产品并发表评论。

我需要在我的产品页面上显示特定产品的信息,而不是所有信息。 (例如,我希望iPad页面上显示iPad的评论)

这是将数据发送到数据库的代码:

<?php
session_start();
include('connection.php');
$name=$_POST['name'];
$product=$_POST['product'];
$star=$_POST['star'];
$comment=$_POST['comment'];
mysql_query("INSERT INTO tt_review(name, product, star, comment)VALUES('$name', '$product', '$star','$comment')");
header("location: https://scm-intranet.tees.ac.uk/users/l1071039/tablet-takeover/index.html");
mysql_close($con);
?>

这是将数据提取到我的页面上的当前代码:

<?php
include('connection.php');
$result = mysql_query("SELECT * FROM tt_review");

echo "<table border='1'>
<tr>

</tr>";

while($row = mysql_fetch_array($result)) //This function is calling the results variable and displaying them within the rows below
{
echo "<tr>"; //this code tells the page to output the table rows that are defined above
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['date'] . "</td>"; //each row is then executed using the table data function
echo "<td>" . $row['product'] . "</td>";
echo "<td>" . $row['star'] . "</td>";
echo "<td>" . $row['comment'] . "</td>";

echo "</tr>";
}
echo "</table>";

?>

这是我网页上表格的屏幕截图(正如我所说,我需要它只显示 ipad 评论。

enter image description here

最佳答案

要仅选择一种产品,您应该在 sql 查询中添加一个 where 子句:

SELECT * FROM tt_review WHERE product = 'Apple iPad'

关于php - 初学者 : php and mysql table issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24888749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com