我有這樣的代碼呼應我從數據庫中的信息:PHP的echo,簡單的foreach問題
<?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']." ". $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 } ?>
你的意思是你看到所有的5個星評級爲每個項目?如果是這樣,你只需要顯示一個匹配id的評級。否則,「all in one div」是什麼意思? – BugFinder
是的,我需要它顯示在每個項目 – Albana
嗯,我的意思是讓我們說我的英語有問題,但想法是你怎麼把它! – Albana