简体   繁体   English

多个单选按钮评级相同

[英]Multiple radio button rating in the same form

I tried to search yet i unable to find out what i am looking for.Please help me.I am working on a rating form which using radio button star for rating,I am using while loop of mysqli_fetch_assoc to pull the date from database.As shown below 我尝试搜索但仍无法找到我想要的东西。请帮我。我正在使用单选按钮星号进行评级的评级表,正在使用mysqli_fetch_assoc的while循环从数据库中提取日期。如下所示

<?php
    $sql = "SELECT * FROM orderdetail,orderuser,food WHERE orderuser.CustomerID=orderdetail.CustomerID AND orderuser.OrderID=orderdetail.OrderID AND orderdetail.FoodID=food.FoodID AND orderuser.confirmstatus=1";
    $result = $conn->query($sql) or die($conn->error);


    while($colum = mysqli_fetch_assoc($result))
    {
?>
<img src="../php/<?php echo $colum['Foodphoto'];?>" style="height:150px;width:150px">
<br>
<?php echo $colum['FoodName'];?>
<br>
<div class="stars">
    <form action="">
        <input class="star star-5" id="rate-5[]" type="radio" name="rate[]" />
        <label class="star star-5" for="rate-5[]"></label>
        <input class="star star-4" id="rate-4[]" type="radio" name="rate[]" />
        <label class="star star-4" for="rate-4[]"></label>
        <input class="star star-3" id="rate-3[]" type="radio" name="rate[]" />
        <label class="star star-3" for="rate-3[]"></label>
        <input class="star star-2" id="rate-2[]" type="radio" name="rate[]" />
        <label class="star star-2" for="rate-2[]"></label>
        <input class="star star-1" id="rate-1[]" type="radio" name="rate[]" />
        <label class="star star-1" for="rate-1[]"></label>
    </form>
</div>
<hr>
<?php
    }
?>

but the rating for the second result is not working,i find out that is due to the problem of name but i tried to edit it by adding the array still not working. 但是第二个结果的评级不起作用,我发现这是由于名称问题造成的,但是我试图通过添加仍然无法工作的数组来对其进行编辑。 And how could i store them into mysql using php?those tutorial i found only using ajax or jquery i need the ratings submit once the user submitted the form. 以及如何使用php将它们存储到mysql中?那些仅使用ajax或jquery发现的教程,一旦用户提交了表单,就需要提交评级。

The problem I think is that you cannot relate the form being submitted with the record so any update will not work as expected. 我认为问题是您无法将提交的表单与记录相关联,因此任何更新都无法按预期进行。 One of the simplest ways to accomplis this would be a hidden field with the ID of the record - the ID can then be used in the update statement - ie: ( pseudo sql update ) 最简单的方法之一是使用记录ID的隐藏字段-然后可以在update语句中使用ID-即:(伪sql update)

update orderdetail set rating=$rate where ID=$id

So, add a hidden field per form like this perhaps 因此,可以像这样在每个表单中添加一个隐藏字段

    while($colum = mysqli_fetch_assoc($result)){
?>

<img src='../php/<?php echo $colum['Foodphoto'];?>' style='height:150px;width:150px'>
<br>
<?php echo $colum['FoodName'];?>
<br>

<div class='stars'>
  <form action=''>
    <input class='star star-5' type='radio' id='rate-5' name='rate' />
    <label class='star star-5' for='rate-5'></label>

    <input class='star star-4' type='radio' id='rate-4' name='rate' />
    <label class='star star-4' for='rate-4'></label>

    <input class='star star-3' type='radio' id='rate-3' name='rate' />
    <label class='star star-3' for='rate-3'></label>

    <input class='star star-2' type='radio' id='rate-2' name='rate' />
    <label class='star star-2' for='rate-2'></label>

    <input class='star star-1' type='radio' id='rate-1' name='rate' />
    <label class='star star-1' for='rate-1'></label>
    <!--
        HIDDEN FIELD WITH ID
    -->
    <input type='hidden' name='id' value='<?php echo $colum['id'];?>' />
  </form>
</div>
<hr>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM