gpt4 book ai didi

php - 试图将 krajee bootstrap 星级评分中的星级评分发送到 mysql 数据库

转载 作者:行者123 更新时间:2023-11-30 22:39:55 26 4
gpt4 key购买 nike

我正在使用以下插件

http://plugins.krajee.com/star-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">';
}

和 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 帖子。希望这会有所帮助。

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;
}
});
});

关于php - 试图将 krajee bootstrap 星级评分中的星级评分发送到 mysql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31404151/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com