Jquery星级评级将所有明星混合在一起

时间:2013-07-03 15:47:41

标签: php jquery css jquery-ui

我正在使用jquery ui小部件星级。在我的查询回声后,所有星星一起显示(如果查询中有超过2条评论,但如果查询中只有1条评论,则一切都是正确的,也是错误的金额)。

以下是代码:

此函数在开始时将数字1指定给数组以了解哪些星星已填充。

  function get_stars ($rating) {
    if( $rating == 0 ) $rating = 1;
    $ratings_array = array_fill (1, 5, 0);
    for ($index=(int)$rating; $index>0; $index--) {
      $ratings_array[$index] = 1;
    }
    return $ratings_array;
  }

我回复并直接在phpmyadmin中尝试查询以确保其有效:

select r.reviews_id, rd.reviews_text, r.reviews_rating, r.date_added, r.customers_name from reviews r join reviews_description rd on rd.reviews_id = r.reviews_id where r.products_id = '40' and rd.languages_id = '1' and reviews_status = '1' order by r.reviews_id DESC

输出2行。 5列就像它应该: reviews_id reviews_text reviews_rating 添加日期 customers_name

这是带有查询的完整while循环,以及回显的表:

                <table border=0 cellspacing=0 cellpadding=0><tbody>
<?php
    if (SPECIFICATIONS_MAX_REVIEWS > '0') {
      $reviews_count_query_raw = "
        select
          count(*) as count
        from
          " . TABLE_REVIEWS . "
        where
          products_id = '" . (int) $_GET['products_id'] . "'
          and reviews_status = '1'
      ";
      // print 'Count Query: ' . $reviews_count_query_raw . '<br>';
      $reviews_count_query = tep_db_query ($reviews_count_query_raw);
      $reviews = tep_db_fetch_array ($reviews_count_query);

      $reviews_query_average_raw = "
        select
          (avg(reviews_rating)) as average_rating
        from
          " . TABLE_REVIEWS . "
        where
          products_id = '" . (int) $_GET['products_id'] . "'
          and reviews_status = '1'
      ";
      // print 'Average Query: ' . $reviews_query_average_raw . '<br>';
      $reviews_query_average = tep_db_query ($reviews_query_average_raw);
      $reviews_average = tep_db_fetch_array ($reviews_query_average);
      $reviews_stars = $reviews_average['average_rating'];

      $reviews_query_raw = "
        select
          r.reviews_id,
          rd.reviews_text,
          r.reviews_rating,
          r.date_added,
          r.customers_name
        from
          " . TABLE_REVIEWS . " r
          join " . TABLE_REVIEWS_DESCRIPTION . " rd
            on rd.reviews_id = r.reviews_id
        where r.products_id = '" . (int) $_GET['products_id'] . "'
          and rd.languages_id = '" . $languages_id . "'
          and reviews_status = '1'
        order by r.reviews_id DESC
      ";
      // print $reviews_query_raw . '<br>';
      $reviews_query = tep_db_query( $reviews_query_raw );
      $num_rows = tep_db_num_rows( $reviews_query );
    echo $reviews_query_raw;
      if ($num_rows > 0) {
        $row = 0;
        while ($reviews = tep_db_fetch_array ($reviews_query)) {
          if ($row < SPECIFICATIONS_MAX_REVIEWS) {
            $row++;
            $date_added = tep_date_short ($reviews['date_added']);
// Show product reviews
?>
                      <tr>
                        <td class="main">

<?php 

                    $rating = get_stars($reviews['reviews_rating']);
                    echo  tep_draw_radio_field ('rating', '1', $rating[1], 'class="star" disabled="disabled"') .
                    ' ' . tep_draw_radio_field ('rating', '2', $rating[2], 'class="star" disabled="disabled"') .
                    ' ' . tep_draw_radio_field ('rating', '3', $rating[3], 'class="star" disabled="disabled"') .
                    ' ' . tep_draw_radio_field ('rating', '4', $rating[4], 'class="star" disabled="disabled"') .
                    ' ' . tep_draw_radio_field ('rating', '5', $rating[5], 'class="star" disabled="disabled"') .
                      sprintf (TEXT_REVIEW_BY, tep_output_string_protected ($reviews['customers_name']) ) .  ', ' .
                          tep_date_long ($reviews['date_added']);

?>
                        </td>
                      </tr>
                      <tr>
                        <td valign="top" class="main">
<?php
            echo tep_break_string (tep_output_string_protected ($reviews['reviews_text']), 60, '<br>') . ( (strlen ($reviews['reviews_text']) >= 100) ? '<br>' : '') .
                                   '... &nbsp; &nbsp;' .
                                   '<a href="' . tep_href_link (FILENAME_PRODUCT_REVIEWS_INFO, 'products_id=' . $product_info['products_id'] . '&reviews_id=' . $reviews['reviews_id']) . '">' .
                                   'Read Full Review</a>';
?>
                        </td>
                      </tr>
<?php
           } // if ($row
         } // while ($reviews
?>
                      <tr>
                        <td><?php echo tep_draw_separator ('pixel_trans.gif', '100%', '10'); ?></td>
                      </tr>
<?php
       } // if ($num_rows
     } // if (SPECIFICATIONS_MAX_REVIEWS

?>
                      <tr>
                        <td><?php echo tep_draw_separator ('pixel_trans.gif', '100%', '10'); ?></td>
                      </tr>
                    </tbody></table>
<?php

最终结果如下:

http://i.imgur.com/LQyGtHG.png

请注意,一个评论是5星,另一个是2星。所以它甚至不是正确的启动量,而是将它们合并在一起。

然而,如果我在这种情况下只有1条评论活跃,那么它将完美地运作2星:

http://i.imgur.com/zipoGqR.png

这是小部件:http://www.fyneworks.com/jquery/star-rating/

0 个答案:

没有答案