dpr26232 2018-06-05 21:50
浏览 41

是否可以在不重新加载页面的情况下重做while循环?

I can use some help with the following. I would like to change the content of my buttons after pressing the button. Is it possible to change a PHP variable from Javascript, or can I not do this because PHP is server-side?

After that I want to run a MySQL query with this new variable and use it in my while loop. I hope someone can help me.

PHP:

<?php 

$result = $conn->query($query_answer);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) 
    {
?>

<input type="button" id="<?php echo $row["answer_id"];?>" next_question_id="<?php echo $row["next_question_id"];?>" value="<?php echo $row["answer_text"];?>" onclick=myFunction((this.id));>

<?php   
    }
}

$conn->close();

?>

JavaScript:

<script>
function myFunction(clicked_id) {
    var button = clicked_id
    var next_question_id = document.getElementById(button).getAttribute("next_question_id"); 
        $.post ('next_question.php',{postnextquestionid:next_question_id},
            function (data) 
            {
                $('#question_text').html(data);
            });

}

</script>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
    • ¥15 这种微信登录授权 谁可以做啊
    • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
    • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
    • ¥15 网络设备配置与管理这个该怎么弄
    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!