PAD Showcase
All tags/Rating

Product reviews

The average score of each product as stars - a part of a star filled as far as the score goes.

1 The data rating/reviews.php php
<?php

  $products = [
    [ 'product' => 'Walnut desk lamp',   'score' => 4.7, 'reviews' => 214 ],
    [ 'product' => 'Linen armchair',     'score' => 4.2, 'reviews' => 88  ],
    [ 'product' => 'Oak side table',     'score' => 3.5, 'reviews' => 41  ],
    [ 'product' => 'Wool rug, 160x230',  'score' => 2.8, 'reviews' => 17  ],
    [ 'product' => 'Ceramic vase',       'score' => 5,   'reviews' => 9   ] ];

?>
2 The template rating/reviews.pad pad
<table style="border-collapse:collapse; width:100%">
  <tr><th style="text-align:left; padding:6px 12px 6px 0">Product</th><th style="text-align:left; padding:6px 12px">Score</th><th style="text-align:right; padding:6px 0">Reviews</th></tr>
  {products}
  <tr style="border-top:1px solid rgba(127,127,127,.25)">
    <td style="padding:8px 12px 8px 0">{$product}</td>
    <td style="padding:8px 12px; white-space:nowrap">{rating $score, size=18} <small>{$score}</small></td>
    <td style="padding:8px 0; text-align:right">{$reviews}</td>
  </tr>
  {/products}
</table>
3 The result rendered on the server
Product Score Reviews
Walnut desk lamp 4.7 out of 5 4.7 214
Linen armchair 4.2 out of 5 4.2 88
Oak side table 3.5 out of 5 3.5 41
Wool rug, 160x230 2.8 out of 5 2.8 17
Ceramic vase 5 out of 5 5 9