PHP - 星级评分1-5

时间:2016-11-23 12:41:50

标签: php html

<table>
<tr>
  <th>name</th>
  <th>startDate</th>
  <th>rating</th>
  <th>underlay</th>
  <th>edges</th>
  <th>grip</th>
  <th>depth</th>
  <th>length</th>
  <th>height</th>
  <th>realname</th>
</tr>
<?php

if(isset($_GET['DS'])){

  $query='SELECT * FROM KundDetaljer where rspName = :DS';
  $stmt = $pdo->prepare($query);
  $stmt->bindParam(':DS', $_GET['DS']);
  $stmt->execute();

  foreach($stmt as $key => $row){
    echo '<tr>';
    echo "<td>".$row['rspName']."</td>";
    echo "<td>".$row['startDate']."</td>";
    echo "<td>".$row['rating']."</td>";
    echo "<td>".$row['underlay']."</td>";
    echo "<td>".$row['edges']."</td>";
    echo "<td>".$row['grip']."</td>";
    echo "<td>".$row['depth']."</td>";
    echo "<td>".$row['length']."</td>";
    echo "<td>".$row['height']."</td>";
    echo "<td>".$row['realname']."</td>";
    echo "</tr>"; 
  }
}
echo "</table>";
?>

嗨,我是瑞典的一名学生,他在向评级中的星号编号方面遇到了问题。上面的代码是显示客户评级的代码。当客户发表评论时,我希望它显示为明星。

1 个答案:

答案 0 :(得分:2)

在foreach内部(在任何回声之前):

$stars = "";
for($i=0;$i<$row["rating"];$i++){
    $stars .= "★";
}

然后代替

echo "<td>".$row['rating']."</td>";

使用

echo "<td>".$stars."</td>";