Problems with php foreach

Asked

Viewed 257 times

0

I made a foreach with PHP and a file.json to simulate a mini shop inside a thumbnail in a slide carousel, however it is not properly appearing one side of the other as it should be. I would like to know where I am missing.

Follow my code and a print from the screen showing how is "bugada" the information.

As it is currently:

inserir a descrição da imagem aqui

PHP:

<div class="slide-best-sallers owl-carousel">
    <div class="item">
        <div class="row">
            <div class="col-md-12 text-center">
                <div class="thumbnail">
                    <?php
                    $json_url = "products.json";
                    $json = file_get_contents($json_url);
                    $links = json_decode($json, TRUE);
                    ?>
                    <?php
                    foreach($links['products'] as $key=>$val){ 
                        ?>
                        <img src="<?php echo $val['imgUrl']; ?>" alt="<?php echo $val['alt']; ?>">
                        <div class="caption" >
                            <p class="description"><?php echo $val['nome']; ?></p>
                            <h3 class="price"><?php echo $val['preco']; ?></h3>
                            <p class="plots"><?php echo $val['parcelas']; ?></p>   
                            <p class="free-shipping">Frete grátis</p>
                            <a href="#" class="btn btn-primary button-salle" role="button">Comprar <i class="fa fa-shopping-cart" aria-hidden="true"></i></a>
                        </div>
                        <?php
                    }
                    ?>
                </div>
            </div>
        </div>
    </div>
    <div class="owl-dots disabled">
        <div class="owl-dot active"><span></span></div>
        <div class="owl-dot"><span></span></div>
    </div>
</div>  

JS from the slide:

//Slide products
$('.slide-best-sallers').owlCarousel({
    loop:true,
    margin:10,
    dots: true,
    loop: true,
    responsiveClass:true,
    responsive:{
        0:{
            items:1
        },
        600:{
            items:3
        },
        1000:{
            items:3,
        }
    }
});

Json file:

{
    "products": [
        {

            "imgUrl": "img/logo.png",
            "alt": "notebook acer",
            "nome" : "notebook 2 em 1 Acer - Windows 10",
            "preco" : "R$999,99",
            "parcelas" : "10x de R$99,00"
        },
        {
            "imgUrl": "img/logo.png",
            "alt": "notebook acer",
            "nome" : "notebook 2 em 1 Acer - Windows 10",
            "preco" : "R$999,99",
            "parcelas" : "10x de R$99,00"
        }
    ]
}
  • Your JSON has a small error in the syntax. In the last line of each item, referring to parcelas, has a comma at the end. JSON does not allow this, so simply remove them and it should work.

  • @Andersoncarloswoss oberigado by the answer but even so did not work

  • Ah, yes, it has the detail that in JSON is products and in PHP you are calling produtos.

  • aaaaaaaaaaaaa muleke vlw turned out that mistake beast

  • @Andersoncarloswoss so that has another problem this foreach has to stay right on my slide Owl Carrousel side by side see so how it turned out I will update the question

  • 1

    I believe that the owl-carousel identifies items through the class .item, but you’re inserting all the images into just one element like this. The correct thing wouldn’t be to generate multiple div.item, one for each image?

  • @Andersoncarloswoss worked out thank you very much if possible add this as a response to mark as accepted

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.