-1
<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>";
?>

Hi, i'm a student in Sweden who is having a problem with making numbers to stars out of rating. The code above is the code that shows the rating from customers. When the comments from customers is made i want it to be showed as stars.

jrbedard
  • 3,662
  • 5
  • 30
  • 34
Joel Silva
  • 11
  • 1

1 Answers1

2

inside foreach (before any echo):

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

Then instead of

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

use

echo "<td>".$stars."</td>";
McCuz
  • 227
  • 1
  • 12
  • No problem. Let me know if you need help understanding the code. (Incase you need to explain in your class what exactly you did here.) – McCuz Nov 23 '16 at 13:57