我正忙着制作一个小评论系统。我希望用户除了发表评论之外还能给出评分,现在我将这些评级值(来自单选按钮)存储在数据库中。但是,当我尝试使用数据库中每个注释的评级值填充单选按钮时,以下脚本仅检查与数据库中最后一个值对应的单选按钮。
<?php
$sql = mysql_query("SELECT * FROM comments WHERE id_post = '$id_post'") or die(mysql_error());;
while($affcom = mysql_fetch_assoc($sql)){
$name = $affcom['name'];
$email = $affcom['email'];
$comment = $affcom['comment'];
$rating = $affcom['rating'];
$date = $affcom['date'];
// Get gravatar Image
// https://fr.gravatar.com/site/implement/images/php/
$default = "mm";
$size = 35;
$grav_url = "http://www.gravatar.com/avatar/".md5(strtolower(trim($email)))."?d=".$default."&s=".$size;
?>
<div class="cmt-cnt">
<img src="<?php echo $grav_url; ?>" />
<div class="thecom">
<h5><?php echo $name; ?></h5><span data-utime="1371248446" class="com-dt"><?php echo $date; ?></span>
<br/>
<p>
<?php echo $comment; ?>
</p>
<p>
<input type="radio" name="hoi" value="1" <?php echo ($rating=='1')?'checked':'' ?> />
<input type="radio" name="hoi" value="2" <?php echo ($rating=='2')?'checked':'' ?> />
<input type="radio" name="hoi" value="3" <?php echo ($rating=='3')?'checked':'' ?> />
<input type="radio" name="hoi" value="4" <?php echo ($rating=='4')?'checked':'' ?> />
<input type="radio" name="hoi" value="5" <?php echo ($rating=='5')?'checked':'' ?> />
</p>
</div>
</div><!-- end "cmt-cnt" -->
<?php } ?>
这是一张现在看起来像的图片:
有人能告诉我如何检查所有方框(基于数据库值)吗?
答案 0 :(得分:0)
我不能正确理解你的问题???
如果您想根据鼠标检查单选按钮,可以这样使用:
<form>
<p>
<input type="radio" name="hoi1" value="1" checked />
<input type="radio" name="hoi2" value="2" />
<input type="radio" name="hoi3" value="3" />
<input type="radio" name="hoi4" value="4" />
<input type="radio" name="hoi5" value="5" />
<input type="radio" name="hoi6" value="5" />
</p>
</form>
<form>
<p>
<input type="radio" name="hoi1" value="1" checked />
<input type="radio" name="hoi2" value="2" checked />
<input type="radio" name="hoi3" value="3" />
<input type="radio" name="hoi4" value="4" />
<input type="radio" name="hoi5" value="5" />
<input type="radio" name="hoi6" value="5" />
</p>
</form>
<form>
<p>
<input type="radio" name="hoi1" value="1" checked />
<input type="radio" name="hoi2" value="2" checked />
<input type="radio" name="hoi3" value="3" checked />
<input type="radio" name="hoi4" value="4" />
<input type="radio" name="hoi5" value="5" />
<input type="radio" name="hoi6" value="5" />
</p>
</form>
<form>
<p>
<input type="radio" name="hoi1" value="1" checked />
<input type="radio" name="hoi2" value="2" checked />
<input type="radio" name="hoi3" value="3" checked />
<input type="radio" name="hoi4" value="4" checked />
<input type="radio" name="hoi5" value="5" />
<input type="radio" name="hoi6" value="5" />
</p>
</form>
<form>
<p>
<input type="radio" name="hoi1" value="1" checked />
<input type="radio" name="hoi2" value="2" checked />
<input type="radio" name="hoi3" value="3" checked />
<input type="radio" name="hoi4" value="4" checked />
<input type="radio" name="hoi5" value="5" checked />
<input type="radio" name="hoi6" value="5" />
</p>
</form>
<form>
<p>
<input type="radio" name="hoi1" value="1" checked />
<input type="radio" name="hoi2" value="2" checked />
<input type="radio" name="hoi3" value="3" checked />
<input type="radio" name="hoi4" value="4" checked />
<input type="radio" name="hoi5" value="5" checked />
<input type="radio" name="hoi6" value="5" checked />
</p>
</form>
&#13;
为标签使用不同的名称。你可以把它们放在表格标签里。
答案 1 :(得分:0)
没关系,修理它。这个名字就是问题所在。对于每组单选按钮,它应该是唯一的;)。 Tnx为您提供帮助Dineth