Php echo,简单的foreach问题
我有一个代码,从数据库中回显我的信息:Php echo,简单的foreach问题,php,Php,我有一个代码,从数据库中回显我的信息: <?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 "&l
<?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>";
}
?>
星级评定员-
试试看(可能有拼写错误,但希望你能理解)
开关($star['id']))
{
案例1:
回音'
';
打破
案例2:
回音'
']
打破
案例3:
回音'
';
打破
案例4:
回音'
';
打破
案例5:
回音“”;
打破
违约:
附和“反对票”;
打破
}
您的意思是您看到每个项目的所有五星评级吗?如果是这样,则只需显示与id评级匹配的id。。否则,你说的“全在一个分区”是什么意思?是的,我需要它显示在每个项目中。嗯,我的意思是说,我的英语有问题,但问题是你怎么说的!这是家庭作业吗??因为其他人发布了完全相同的东西,谢谢,但是我应该在我自己的代码中插入到哪里呢?我的意思是,所有这些创造了一个评级系统与5颗星,我需要每个评级系统显示在每个配置文件我打印在第一个脚本。。。为了工作,需要第二个脚本的全部代码。。是的,这对我们来说是一种家庭作业,由于你的回答,我得到了我需要的结果,但我的朋友需要另一种输出。:)
<?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 } ?>
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;
}