how do I edit the output of fgetcsv

I’m using eKomi and want to pull in reviews to my website. I’ve managed to get this working but there’s a slight problem. Currently every single review is getting added, and in reverse order.

You’ll see from the code below that I am using fgetcsv.

Read More

Is it possible to limit to the 12 latest reviews? and then order them from newest to oldest?

Here’s the code I’ve put together.

    <div class="row">
    <div class="row__colspaced">
        <?php
        $row = 1;
        if (($handle = fopen("http://api.ekomi.de/get_feedback.php?interface_id=66630&interface_pw=f2d097e83db1880e85e2f77aa&range=3m&type=csv", "r")) !== FALSE) {
            while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        echo "<div class='colspan12-4 colspan6-3 as-grid with-gutters'><div class='content-module--review-list__item item' data-mh='review-item'>";
                $num = count($data);
                $row++;

            for ($c=0; $c < $num; $c++) {
                if($c == 0){
                    echo gmdate('Y-m-d H:i:s',$data[$c]);
                }
                else if($c == 2){
                    if($data[$c] == 1){
                            echo '<div class="fa-star-rating">
                                    <i class="fa fa-star"></i>
                                    <i class="fa fa-star-o"></i>
                                    <i class="fa fa-star-o"></i>
                                    <i class="fa fa-star-o"></i>
                                    <i class="fa fa-star-o"></i>
                                </div>';
                    }
                    if($data[$c] == 2){
                            echo '<div class="fa-star-rating">
                                    <i class="fa fa-star"></i>
                                    <i class="fa fa-star"></i>
                                    <i class="fa fa-star-o"></i>
                                    <i class="fa fa-star-o"></i>
                                    <i class="fa fa-star-o"></i>
                                </div>';
                        }
                    if($data[$c] == 3){
                            echo '<div class="fa-star-rating">
                                    <i class="fa fa-star"></i>
                                    <i class="fa fa-star"></i>
                                    <i class="fa fa-star"></i>
                                    <i class="fa fa-star-o"></i>
                                    <i class="fa fa-star-o"></i>
                                </div>';
                        }
                    if($data[$c] == 4){
                            echo '<div class="fa-star-rating">
                                    <i class="fa fa-star"></i>
                                    <i class="fa fa-star"></i>
                                    <i class="fa fa-star"></i>
                                    <i class="fa fa-star"></i>
                                    <i class="fa fa-star-o"></i>
                                </div>';
                        }
                    if($data[$c] == 5){
                            echo '<div class="fa-star-rating">
                                    <i class="fa fa-star"></i>
                                    <i class="fa fa-star"></i>
                                    <i class="fa fa-star"></i>
                                    <i class="fa fa-star"></i>
                                    <i class="fa fa-star"></i>
                                </div>';
                        }

                }
                else {
                    echo '<div class="inner-item item'.$c.'">' . $data[$c] . "</div>";
                }
            }

            echo "</div></div>";
                }
                fclose($handle);
            }
            ?>
    </div>
</div>

Related posts