samedi 29 décembre 2018

conditional statement in carousel

please I need help with this code of mine. I am trying to display only fields from my SQL table with contents in my carousel. I do not want the carousel to always slide into an empty item and display a broken photo icon at the top right corner.

                                $query = "SELECT * FROM property where id = '".$id."' ";
                                $result_new = mysqli_query($con, $query) or die("Could not execute query");
                                while ($row = mysqli_fetch_array($result_new))
                                {

                                $picture1 = "propertyphotos/".$row['picture1'];
                                $picture2 = "propertyphotos/".$row['picture2'];
                                $picture3 = "propertyphotos/".$row['picture3'];
                                $picture4 = "propertyphotos/".$row['picture4'];

                                   if(!empty($row['picture1']))
                                        {
                                           $pic1= '<div class="item active">
                                            <img class="s-property-image" src="<?php echo $picture1; ?>" />
                                            </div>';
                                        }

                                    if(!empty($row['picture2']))
                                        {
                                           $pic2= '<div class="item active">
                                            <img class="s-property-image" src="propertyphotos/<?php echo $picture2; ?>" />
                                            </div>';
                                        }

                                    if(!empty($row['picture3']))
                                        {
                                           $pic3= '<div class="item active">
                                            <img class="s-property-image" src="propertyphotos/<?php echo $picture3; ?>" />
                                            </div>';
                                        }

                                    if(!empty($row['picture4']))
                                        {
                                           $pic4= '<div class="item active">
                                            <img class="s-property-image" src="propertyphotos/<?php echo $picture4; ?>" />
                                            </div>';
                                        }

                                }
                                ?>
                                <?php echo $pic1; ?>
                            </div>

Or if there is a better to this i would love to learn. thank you

Aucun commentaire:

Enregistrer un commentaire