我想使用PHP和MySQL制作评论系统。我做了一个名为“注释”表中存储的细节在mysql的一列中选择多个具有相同值的行?
id | date |product_id | user_name | email_id | comment | | | | | 1 |2013-05-07 | 10001 | jabong | [email protected] | this is good product 2 |2013-05-07 | 10001 | john | [email protected] | I bought this product
等
现在我想选择和打印所有那些具有的product_id = 10001行。 我使用下面的代码打印细节
$comment="";
$id=$_GET['id'];//this is the product_id which is taken from URL
$query=mysql_query("SELECT * FROM comment WHERE product_id='$id'");
while($data = mysql_fetch_array($query))
{
$name = $data["user_name"];
$email = $data["email_id"];
$comment = $data["comment"];
$date=strftime("%d %b, %Y", strtotime($data["date"]));
$comment.='<table>
<tr>
<td>Date: '.$date.'</td>
</tr>
<tr>
<td>Name: '.$name.'</td>
</tr>
<tr>
<td>Email_id: '.$email.'</td>
</tr>
<tr>
<td>Product Review: '.$comment.'</td>
</tr>
</table><hr />';
,然后我回响着他们的主体部分。但我只得到一个结果。 所以请帮助我获得正确的代码。
为什么多次使用'$ comment'变量,它必须被覆盖。尝试给出不同的变量名称。 – Rikesh 2013-05-07 16:08:34
您是否尝试过在phpMyAdmin中的sql请求,例如...您有几个结果? – mlwacosmos 2013-05-07 16:10:32