douxiong5972 2015-07-14 10:31
浏览 82

试图将星级评级从krajee bootstrap星级评级发送到mysql数据库

I am using the following plugin

http://plugins.krajee.com/star-rating

I'm trying to send the rating submitted to the database but the values are not being recorded.

require_once $doc_root . '/includes/act_initiate_article_xref.php';

    $rating_value = (@$user_article_xref_row['rating'] > 0) ? $user_article_xref_row['rating'] . ' stars' : 'unrated';
    $article_rating = '<span class="line-sep">Rated:</span> ' . $rating_value;
if ($_SESSION['user_id'] == 1 || $_SESSION['user_id'] == 41)    {
    $rating_value_attr = (isset ($user_article_xref_row['rating'])) ? ' value="' . $user_article_xref_row['rating'] . '"' : '';
    $article_rating .= '<span class="line-sep">Your rating: </span> <input id="input-21d" type="number" class="rating"' . $rating_value_attr . ' data-min=0 data-max=5 step=0.5 data-size="xs">';
}

and the code for act_initiate_article_xref.php

<?

/**
 * reads user_article_xref
 */
$this_routine[] = "includes/act_initiate_article_xref.php";

/**
 * no direct access allowed
 */
$doc_root = $_SERVER['DOCUMENT_ROOT'];
require_once $doc_root . '/includes/act_check_valid_access.php';

$table_title = 'user_article_xref';

$user_id = (isset ($_SESSION['user_id'])) ? $_SESSION['user_id'] : 0;

$fields = '`id`, `hits`, `rating`';
$match_where = '`user_id` = ' . $user_id . ' and `article_id` = ' . $article_id;
$article_result = $db->selectByStrings($fields, $table_title, $match_where, null, 1);
#if ($_SESSION['user_id'] == 1) { echo "<br>21. select $fields from $table_title where $match_where<pre>";print_r($_SESSION);echo "</pre>"; }

/**
 * if there is already a record, update it
 * if there isn't already a record, insert it
 * either way, $user_article_xref_row holds details for any ajax rating update
 */
if ($db->getNumRows($article_result) > 0)   {
    $user_article_xref_row = $db->getNextRow($article_result);
    $hits = $user_article_xref_row['hits'] + 1;
    $pairs_array = array ('hits' => $hits);
    $id_where = '`id` = ' . $user_article_xref_row['id'];
    $update_result = $db->updateByArray($table_title, $pairs_array, $id_where);
    $test = 'update';
} else {
    $hits = 1;
    $user_article_xref_row = array ('user_id' => $user_id, 'article_id' => $article_id, 'hits' => $hits);
    $insert_result = $db->insertByArray($table_title, $user_article_xref_row);
    $test = 'insert';
}
#if ($_SESSION['user_id'] == 1) { echo "<br>37. $test<pre>";print_r($user_article_xref_row);echo "</pre>"; }

?>
  • 写回答

1条回答 默认 最新

  • duanlou7910 2015-09-11 21:24
    关注

    I know this post is a little old but just in case. In the star-rating.js I added an ajax post to my php file to the set.listenClick function. Hope this helps.

    self.listenClick(self.$rating, function(e) {
                    if (self.inactive) {
                        return false;
                    }
                    pos = self.getPosition(e);
                    var div_id = self.$element.attr('id');
                    self.setStars(pos);
                    self.$element.trigger('change').trigger('rating.change', [self.$element.val(), self.$caption.html()]);
                    self.starClicked = true;
                    var rating = self.$element.val();
                    $.ajax({
                    type:"POST",
                    url:"rating.php",
                    data:"div="+div_id+"&rating="+rating,
                    success: function(res){
                     console.log("Rating was posted " + div_id + rating);
                                                 return res;
                    }
                });
                });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)