-2

我有这段代码从数据库中呼应了我的信息:

<?php
  include('db_connect.php');
  mysql_query("SET NAMES UTF8");

$sql =" select * from hostess";
$query = mysql_query($sql);


    while ($row = mysql_fetch_array($query)) { 
    echo "<div id='photo'>"; 
    echo "<div id='picture'>"; 
     echo "<td> <img src=foto/photo1/".$row['photo'] . "></td>";
     echo "</div>"; 
echo "<div id='rating'>"; 
     echo "</div>"; 
     echo "<div id='text'>"; 
     echo '<td><a href="hostess.php?id='.$row['id'].'">'. $row['first_name_en']."&nbsp;". $row['family_name_en']."</a></td>";
    echo "</div>"; 
    echo "</div>"; 
    }
    ?>

我还有一个评级系统,我想将它提取到每个 ID。我的问题是,我如何将每个评级分配给每个 id,我的意思是每个人都必须有自己的评级,他们不应该像现在那样在一个 div 中显示所有内容。我需要在每个评分 div 中显示结果。

我用于所有结果的代码是:

<?php 
// include update.php
include_once 'update.php';
// get all data from tabel
$arr_star = fetchStar();
?>
<?php 
// start looping datas
foreach($arr_star as $star){ ?>
<h2>Star Rater - <?php echo $star['id'];?></h2>
<ul class='star-rating' id="star-rating-<?php echo $star['id'];?>">
<?php /* getRating($id) is to generate current rating */?>
  <li class="current-rating" id="current-rating-<?php echo $star['id'];?>" style="width:<?php echo getRating($star['id'])?>%"><!-- will show current rating --></li>
  <?php 
  /* we need to generate 'id' for star rating.. this 'id' will identify which data to execute  */
  /* we will pass it in ajax later */
  ?>
  <span class="ratelinks" id="<?php echo $star['id'];?>">
  <li><a href="javascript:void(0)" title="1 star out of 5" class="one-star">1</a></li>
    <li><a href="javascript:void(0)" title="1 star and a half out of 5" class="one-star-half">1.5</a></li>
  <li><a href="javascript:void(0)" title="2 stars out of 5" class="two-stars">2</a></li>
    <li><a href="javascript:void(0)" title="2 star and a half out of 5" class="two-star-half">2.5</a></li>
  <li><a href="javascript:void(0)" title="3 stars out of 5" class="three-stars">3</a></li>
    <li><a href="javascript:void(0)" title="3 star and a half out of 5" class="three-star-half">3.5</a></li>
  <li><a href="javascript:void(0)" title="4 stars out of 5" class="four-stars">4</a></li>
    <li><a href="javascript:void(0)" title="4 star and a half out of 5" class="four-star-half">4.5</a></li>
  <li><a href="javascript:void(0)" title="5 stars out of 5" class="five-stars">5</a></li>
  </span>
</ul>
<?php } ?>
4

1 回答 1

0

试试(可能有错别字,但希望你明白)

 switch ($star['id'])
{
 case 1:
 echo '  <li><a href="javascript:void(0)" title="1 star out of 5" class="one-star">1</a></li> 
    <li><a href="javascript:void(0)" title="1 star and a half out of 5" class="one-star-half">1.5</a></li>';
 break;
 case 2: 
 echo '  <li><a href="javascript:void(0)" title="2 stars out of 5" class="two-stars">2</a></li> 
    <li><a href="javascript:void(0)" title="2 star and a half out of 5" class="two-star-half">2.5</a></li> ']
 break;
 case 3: 
  echo '  <li><a href="javascript:void(0)" title="3 stars out of 5" class="three-stars">3</a></li> 
    <li><a href="javascript:void(0)" title="3 star and a half out of 5" class="three-star-half">3.5</a></li> '; 
  break;
 case 4:
 echo '  <li><a href="javascript:void(0)" title="4 stars out of 5" class="four-stars">4</a></li> 
    <li><a href="javascript:void(0)" title="4 star and a half out of 5" class="four-star-half">4.5</a></li> ';
  break;
 case 5:
  echo '  <li><a href="javascript:void(0)" title="5 stars out of 5" class="five-stars">5</a></li> ';
 break;
 default :  
  echo 'No vote';
  break;
}
于 2012-07-04T15:11:04.163 回答