Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在数据库中保存评级_Php_Jquery_Jquery Plugins - Fatal编程技术网

Php 在数据库中保存评级

Php 在数据库中保存评级,php,jquery,jquery-plugins,Php,Jquery,Jquery Plugins,我正在使用jQuery插件对我在PHP驱动的网站上发表的每一篇文章进行评级 我使用的插件叫做Raty,可以找到 我想知道如何保存这个评级,因为我可以点击星星,然后得到5星评级,但是如果我刷新页面,评级就消失了 所以我应该以某种方式保存它。首先,您应该在数据库中为此创建一个表 // rate.php - the php page where you will insert rating. $('#rate').raty({ click: function(score) { var

我正在使用jQuery插件对我在PHP驱动的网站上发表的每一篇文章进行评级

我使用的插件叫做Raty,可以找到

我想知道如何保存这个评级,因为我可以点击星星,然后得到5星评级,但是如果我刷新页面,评级就消失了


所以我应该以某种方式保存它。

首先,您应该在数据库中为此创建一个表

// rate.php - the php page where you will insert rating.

$('#rate').raty({
    click: function(score) {
    var id = // get the id of the object for which the rating is done
        $.post('rate.php', {score:score,id:id}, function(data) {
         // data is a variable that may or may not be 
             returned from the rate.php page

            });

    }
});

单击星号后,将(使用Ajax)费率信息发送到服务器并插入到表中。

您可以在此处使用Ajax将最新的费率(整数)以及其他必要的详细信息发送到php页面。然后将评级保存到数据库中

// rate.php - the php page where you will insert rating.

$('#rate').raty({
    click: function(score) {
    var id = // get the id of the object for which the rating is done
        $.post('rate.php', {score:score,id:id}, function(data) {
         // data is a variable that may or may not be 
             returned from the rate.php page

            });

    }
});

您可以为click事件尝试以下操作:(示例代码)


SaveMyRating.php应该是接收提交的分数并保存它(文件或数据库等)的php脚本。

我已经有一个名为posts的表,其中有一个名为rating的字段。所以我只需要加上评级就可以了?刷新后,我需要调用我的数据库以获得评级并将其输入stars?是的,您的逻辑是正确的。Ajax在这里起着重要作用。我敢打赌,使用jQuery做这项工作并不困难。好吧,这就引出了另一个问题。编码所有这些,哈哈!我要去寻找它。已经谢谢了;)您必须记住从数据库、cookie或某种持久数据中读取此值,以使其正常工作。