-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に割り当てることができるかということです。つまり、それぞれが独自の評価を持っている必要があり、現在のようにすべてを1つの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 に答える