Php 修复此评级问题,在错误的帖子上添加评级
我很难找到问题,显示骷髅头的帖子有6条买家评论和5星级评级,该作者拥有的其他帖子如何获得相同的评级和星级,明星和评级应该只显示在给它的帖子上 这是一个小代码,让这个明星了。 这是在这些框中显示星星的代码行Php 修复此评级问题,在错误的帖子上添加评级,php,wordpress,Php,Wordpress,我很难找到问题,显示骷髅头的帖子有6条买家评论和5星级评级,该作者拥有的其他帖子如何获得相同的评级和星级,明星和评级应该只显示在给它的帖子上 这是一个小代码,让这个明星了。 这是在这些框中显示星星的代码行 if(!function_exists('PricerrTheme_my_account_reviews_area_function')) { function PricerrTheme_my_account_reviews_area_function() { global $curr
if(!function_exists('PricerrTheme_my_account_reviews_area_function'))
{
function PricerrTheme_my_account_reviews_area_function()
{
global $current_user;
get_currentuserinfo();
$uid = $current_user->ID;
//-------------------------------------
global $wpdb,$wp_rewrite,$wp_query;
$third_page = $wp_query->query_vars['third_page'];
$third_page = $_GET['pg'];
if(empty($_GET['pg'])) $third_page = 'home';
?>
<div id="content" class="directly-frame account-cnt">
<!-- page content here -->
<div class="box_title3"><?php _e("My Ratings",'PricerrTheme'); ?></div>
<div class="my_box3"><div class="shopping_menu_dv">
<?php
$using_perm = PricerrTheme_using_permalinks();
if($using_perm) $rev_pg_lnk = get_permalink(get_option('PricerrTheme_my_account_reviews_page_id')). "/?";
else $rev_pg_lnk = get_bloginfo('siteurl'). "/?page_id=". get_option('PricerrTheme_my_account_reviews_page_id'). "&";
?>
<ul id="shopping_menu">
<li><a <?php echo ($third_page == "home" ? 'class="actiove"' : ""); ?> href="<?php echo $rev_pg_lnk; ?>"><?php _e("Ratings to Award","PricerrTheme"); ?></a></li>
<li><a <?php echo ($third_page == "waiting" ? 'class="actiove"' : ""); ?> href="<?php echo $rev_pg_lnk; ?>pg=waiting"><?php _e("Pending Ratings","PricerrTheme"); ?></a></li>
<li><a <?php echo ($third_page == "my_rev" ? 'class="actiove"' : ""); ?> href="<?php echo $rev_pg_lnk; ?>pg=my_rev"><?php _e("My Ratings","PricerrTheme"); ?></a></li>
</ul>
</div></div>
<?php
if($third_page == "home"):
?>
<div class="my_box3">
<div class="padd10">
<script>
jQuery(document).ready(function() {
jQuery('.dd-submit-rating').click(function() {
var id = jQuery(this).attr('rel');
var uprating = jQuery("#rating_me-" + id + " :selected").val();
var reason = jQuery("#reason-" + id).val();
if(reason.length < 10) { alert("<?php _e('Please input a longer description for your rating','PricerrTheme'); ?>"); return false; }
jQuery.ajax({
type: "POST",
url: "<?php echo get_bloginfo('siteurl'); ?>/",
data: "rate_me=1&ids="+id+"&uprating="+uprating+"&reason="+reason,
success: function(msg){
jQuery("#post-" + id).hide('slow');
}
});
return false;
});
//-------------------------
});
</script>
<?php
global $wpdb;
$query = "select distinct *, ratings.id ratid from ".$wpdb->prefix."job_ratings ratings, ".$wpdb->prefix."job_orders orders where
ratings.awarded='0' AND orders.id=ratings.orderid AND orders.uid='$uid'";
$r = $wpdb->get_results($query);
if(count($r) > 0)
{
foreach($r as $row)
{
$post = $row->pid;
$post = get_post($post);
$user = get_userdata($row->touser);
?>
<div class="post" id="post-<?php echo $row->ratid; ?>">
<div class="padd10_only">
<div class="image_holder3">
<a href="<?php the_permalink(); ?>"><img width="65" height="50"
src="<?php echo PricerrTheme_get_first_post_image($row->pid,65,50); ?>" /></a>
</div>
<div class="title_holder3" >
<h2><a href="<?php echo get_permalink($row->pid); ?>"><?php echo PricerrTheme_wrap_the_title($post->post_title,$row->pid); ?></a></h2>
<div class="c111">Rate:</div>
<div class="c111"><textarea id="reason-<?php echo $row->ratid; ?>" rows="2" cols="35"></textarea></div>
<div class="c111"> <select name="rating_me" id="rating_me-<?php echo $row->ratid; ?>">
<option value="5">5</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
</div>
<div class="c111 ck999">
<a href="#" rel="<?php echo $row->ratid; ?>" class="dd-submit-rating"><?php _e('Submit Rating Now','PricerrTheme') ?></a>
</div>
</div>
</div>
</div>
<?php
}
}
else
{
_e("There are no reviews to be awarded.","PricerrTheme");
}
?>
</div></div>
<?php elseif($third_page == "waiting"): ?>
<div class="my_box3">
<div class="padd10">
<?php
global $wpdb;
$query = "select distinct * from ".$wpdb->prefix."job_ratings ratings, ".$wpdb->prefix."job_orders orders,
".$wpdb->prefix."posts posts where posts.ID=orders.pid AND
ratings.awarded='0' AND orders.id=ratings.orderid AND posts.post_author='$uid'";
$r = $wpdb->get_results($query);
if(count($r) > 0)
{
foreach($r as $row)
{
$post = $row->pid;
$post = get_post($post);
$user = get_userdata($row->uid);
?>
<div class="post" id="post-<?php echo $row->ratid; ?>">
<div class="padd10_only">
<div class="image_holder3">
<a href="<?php the_permalink(); ?>"><img width="65" height="50"
src="<?php echo PricerrTheme_get_first_post_image($row->pid,65,50); ?>" /></a>
</div>
<div class="title_holder3" >
<h2><a href="<?php echo get_permalink($row->pid); ?>"><?php echo PricerrTheme_wrap_the_title($post->post_title,$row->pid); ?></a></h2>
<?php echo sprintf(__('Waiting from: %s','PricerrTheme'), $user->user_login ); ?>
</div>
</div>
</div>
<?php
}
}
else
{
_e("You have no pending reviews.","PricerrTheme");
}
?>
</div>
</div>
<?php elseif($third_page == "my_rev"): ?>
<div class="my_box3">
<div class="padd10">
<?php
global $wpdb;
$query = "select distinct *, ratings.id ratid from ".$wpdb->prefix."job_ratings ratings, ".$wpdb->prefix."job_orders orders,
".$wpdb->prefix."posts posts where posts.ID=orders.pid AND
ratings.awarded='1' AND orders.id=ratings.orderid AND posts.post_author='$uid'";
$r = $wpdb->get_results($query);
if(count($r) > 0)
{
foreach($r as $row)
{
$post = $row->pid;
$post = get_post($post);
$user = get_userdata($row->touser);
?>
<div class="post" id="post-<?php echo $row->ratid; ?>">
<div class="padd10_only">
<div class="image_holder3">
<a href="<?php the_permalink(); ?>"><img width="65" height="50"
src="<?php echo PricerrTheme_get_first_post_image($row->pid,65,50); ?>" /></a>
</div>
<div class="title_holder3" >
<h2><a href="<?php echo get_permalink($row->pid); ?>"><?php echo PricerrTheme_wrap_the_title($post->post_title, $row->pid); ?></a></h2>
<div class="c111"><b><?php _e("Rated","PricerrTheme"); ?>: </b></div>
<div class="c111"><?php
echo PricerrTheme_show_stars_our_of_number($row->grade);
?>
</div>
<div class="clear10" style="float:left"></div>
<div class="c111"><b><?php _e("Description","PricerrTheme"); ?>: </b></div>
<div class="c111"><?php echo stripslashes($row->reason); ?>
</div>
</div>
</div>
</div>
<?php
}
}
else
{
_e("You have no reviews.","PricerrTheme");
}
?>
</div></div>
<?php endif; ?>
<!-- page content here -->
</div>
<?php
PricerrTheme_get_users_links();
} }
尝试使用author和post Id或just post Id获取查询:因为post独立于其Id,并且它们是唯一的,但是post author只是与post相关,而不是独立的,因为authoruid可以有多个post,但是post将有一个唯一的post Id(&U) 我假设现在post Id也在同一个表中。给你举一个postId和authoruid的例子 范例
echo pricerrtheme_show_rating_star_user($post->post_author, $post_id);
同样的方法修改函数和mysql查询
功能:
和查询
最终代码
希望这有帮助Krishcdby是我见过的最优秀的php大师之一,我从未见过像Krishcdby这样有才华、经验丰富的程序员,最棒的是他如此耐心、冷静、充满爱心、热情,而且非常乐于助人,这位绅士应该为他的工作大师皮埃斯获得一个更高的评级。以上提供的代码是针对单个职位的吗?当你写这行时,$nr_ratings=$r[0]>cnt$总和=$r[0]->smm;这些都指定了[0]它不是循环的是单个post它们中的每一个,我能做些什么来解决这个问题?如果不是那么多boss,请您帮忙谢谢。仅供参考,您可以在SQL中使用AVGgrade,而不是在PHP中计算它。您需要将$post_id传递给函数,并在查询中使用它,而不是$post_author。$post_id=获取_id;echo pricerrtheme\u show\u rating\u star\u用户$post\u id;函数pricerrtheme\u show\u rating\u star\u user$uid,$postid{…}我得到一个白色页面,目前我有这个函数pricerrtheme\u show\u rating\u star\u user$uid它的结尾行可能是什么?我试着只添加pricerrtheme\u show\u rating\u star\u user$uid,$postid仍然是白色页面,尝试与我现在提供的pricerrtheme\u show\u rating\u star\u user$post->post\u author,$post\u id相同;函数pricerrtheme\u show\u rating\u star\u user$uid,$postid{..}和mysql查询与我的答案相同在那之前,首先告诉我表中postid的postid列名是什么我添加了这行函数pricerrtheme\u show\u rating\u star\u user$uid,$postid no white page并按照指示添加了其他代码all white stars。是的,这是由于mysql函数不返回任何行,因此需要正确指定列名请在skype hanna21460上添加我的广告。我将于明天登录skype,因为我的skype安装已中断,它将显示我的页面,所以我需要再次安装我thk请给我发送请求,我接受你,我很乐意在另一端为你服务谢谢你再次向你发送请求hanna dean对吗?来自英国
function pricerrtheme_show_rating_star_user($uid, $post_id) { ..... }
$s = "select count(grade) cnt, sum(grade) smm from ".$wpdb->prefix."job_ratings where uid='$uid' and awarded='1' and pid='$post_id'";
function pricerrtheme_show_rating_star_user($uid, $post_id) {
$concat = '';
$nr_ratings = 0;
global $wpdb;
$s = "select count(grade) cnt, sum(grade) smm from ".$wpdb->prefix."job_ratings where uid='$uid' and awarded='1' and pid='$post_id'";
$r = $wpdb->get_results($s);
if(count($r) > 0)
{
$nr_ratings = $r[0]->cnt;
$sum = $r[0]->smm;
if($nr_ratings > 0)
{
if($sum > 0)
$sdd = ceil($sum/$nr_ratings);
else $sdd = 1;
for($i=1;$i<=$sdd;$i++)
{
$concat .= ' <img src="'.get_bloginfo('template_url').'/images/star_full.png" width="15" />';
}
for($i=$sdd+1;$i<=5;$i++)
{
$concat .= ' <img src="'.get_bloginfo('template_url').'/images/star_empty.png" width="15" />';
}
}
else
{
$concat = '';
for($i=1;$i<=5;$i++)
{
$concat .= ' <img src="'.get_bloginfo('template_url').'/images/star_empty.png" width="15" />';
}
}
}
else
{
$concat = '';
for($i=1;$i<=5;$i++)
{
$concat .= ' <img src="'.get_bloginfo('template_url').'/images/star_empty.png" width="15" />';
}
}
return $concat." (".$nr_ratings.")";
}