Php 正在尝试将星级从krajee引导星级发送到mysql数据库
我正在使用以下插件 我正在尝试将提交的评分发送到数据库,但没有记录这些值Php 正在尝试将星级从krajee引导星级发送到mysql数据库,php,jquery,mysql,Php,Jquery,Mysql,我正在使用以下插件 我正在尝试将提交的评分发送到数据库,但没有记录这些值 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 =
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">';
}
require\u once$doc\u root.'/包括/act_initiate_article_xref.php';
$rating_value=(@$user_article_xref_row['rating']>0)$用户\文章\外部参照\行['rating'].'星星:'未分级';
$article_rating=‘Rated:’$额定值;
如果($_会话['user_id']==1 | |$_会话['user_id']==41){
$rating_value_attr=(isset($user_article_xref_row['rating'])?'value=“”。$user_article_xref_row['rating']):“”;
$article_rating.=“您的评级:”;
}
以及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>"; }
?>
我知道这篇文章有点过时,但只是以防万一。在star-rating.js中,我在set.listenClick函数的php文件中添加了一个ajax帖子。希望这有帮助
我知道这篇文章有点旧,但只是以防万一。在star-rating.js中,我在set.listenClick函数的php文件中添加了一个ajax帖子。希望这有帮助
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;
}
});
});