gpt4 book ai didi

mysql - 如何根据数据库值检查所有单选按钮?

转载 作者:行者123 更新时间:2023-11-30 22:26:18 26 4
gpt4 key购买 nike

我正在忙着做一个小小的评论系统。我希望用户能够给出评级,除了给出评论,现在我将这些评级值(来自单选按钮)存储在数据库中。但是,当我尝试使用数据库中每个评论的评分值填充单选按钮时,以下脚本仅检查与数据库中最后一个值对应的单选按钮。

    <?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 } ?>

这是它现在的样子:

enter image description here

谁能告诉我如何选中所有复选框(基于数据库值)?

最佳答案

我没有正确理解你的问题???

如果你想根据等级检查单选按钮,你可以这样使用:

<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>

为标签使用不同的名称。您可以将它们放在表单标签内。

关于mysql - 如何根据数据库值检查所有单选按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35113988/

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