Вопрос

I have a grid with a little voting system. There are dates listed in every row with a + at the end of each row, which is used to vote. Here´s an image: http://doubledream.square7.de/upload/dates.PNG the white text displays the dates, the green text the ranking and the + is for upvoting.

Everything works so far, except for the upvoting, I just can´t get the id right.

I first tried to simply put $id in the where constraint, which always updated the last row. Secondly I tried to add <input type="hidden" name="idupdate" value="'. $id. '" />'; to the while clause.

Then I put $idupdate in the where constraint, but that does absolutely nothing.

I Hope this fraction of code is enough:

  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
    <script src="http://malsup.github.com/jquery.form.js"></script> 
  </head>

<?php
    require("connect.php");
    $getquerydate=mysql_query("SELECT * FROM table where staid=1 order by id asc");
    while($rows=mysql_fetch_assoc($getquerydate)) {
        $id=$rows['id'];
        $text=$rows['datum'];
        $vote=$rows['vote'];
        $staid=$rows['staid'];
        echo '
            <font color="white">' . $text. '</font>&nbsp;
            <font color="#00FF00">' . $vote . '</font>&nbsp;

            <form style="display:inline!important;" id="datplus" name="datplus" 
            action="mysite.php" method="post" ><input type="submit" 
            name="submitdatplus" class="submit" value="+" /></form>

            <input type="hidden" name="idupdate" value="'. $id. '" /><br>';
    }
    $idupdate=$_POST['idupdate'];
    $submitdatplus=$_POST['submitdatplus'];

?>
<script>
        $(document).ready(function() { 
            $('[name=datplus]').ajaxForm(function() { 
            <?php
                $vote= $vote+1;

                if($submitdatplus) {
                    mysql_query("UPDATE table set vote='$vote' 
                                    where id='$idupdate'");
                }
            ?>
            }); 
        }); 
</script>

Thanks in advance

Это было полезно?

Решение

<input type="hidden" name="idupdate" value="'. $id. '" /><br>';

Hidden field should be inside your <form> not after it.

Close the form after your hidden field.

echo '
            <font color="white">' . $text. '</font>&nbsp;
            <font color="#00FF00">' . $vote . '</font>&nbsp;

            <form style="display:inline!important;" id="datplus" name="datplus" 
            action="mysite.php" method="post" ><input type="submit" 
            name="submitdatplus" class="submit" value="+" />

            <input type="hidden" name="idupdate" value="'. $id. '" /><br>

</form>';
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top