5
I have a PHP code that pulls an XML and plays on the screen but I would like it to run in random order and not the order that is in XML.
That’s possible?
Code I’m using.
PHP
$xml = simplexml_load_file('produtos.xml');
foreach ($xml as $oferta){
$a = "<div class='produto'><a href=" . $oferta->links->link["url"]. ">". $oferta->offerName. "</a><br>";
$a .= "" . $oferta->offerShortName. "<br>";
$a .= "<img src=" . $oferta->thumbnail["url"]. " width='80%;'><br>";
$a .= "R$" . $oferta->price->value.  "<br>";
$a .= "<a href=" . $oferta->links->link["url"]. ">comprar</a><br>"; 
$a .= "<a href=" . $oferta->links->link["url"]. "><img src=" . $oferta->seller->thumbnail["url"]. "></a><br></div>";
echo $a;
XML
<offer categoryId="5" id="149417086" productId="599409">
    <offerName>DVD Portátil Tectoy Bob Esponja DVT - P4000 ( 117700377 )</offerName>
    <offerShortName>Dvd Portátil </offerShortName>
    <links>
        <link url="http://links.lomadee.com/ls/of/Y249Z1F3RjttZHNyYz0zMzU4MzI4NTtlbXBfaWQ9ODE7bWRhcHA9NTc5ODtwcm9kX2lkPTE0OTQxNzA4Njt4bGs9aHR0cDovL3d3dy5hbWVyaWNhbmFzLmNvbS5ici9wcm9kdXRvLzExNzcwMDM3Ny9kdmQtcG9ydGF0aWwtdGVjdG95LWJvYi1lc3BvbmphLWR2dC1wNDAwMD87Y291bnRyeT1CUjtodD02YzRlZTg1ZjcyNjhmYzVjODdmOWE3NTJjZDZhNDE2NDttZGR0bj0w.html" type="offer"/>
    </links>
    <thumbnail url="http://iacom.s8.com.br/produtos/01/00/item/117700/3/117700377_1GG.jpg"/>
    <price>
        <currency abbreviation="BRL"/>
        <value>296.88</value>
    </price>
    <seller id="81" isTrustedStore="true" pagamentoDigital="false" advertiserId="0" oneClickBuy="false" oneClickBuyValue="0" cpcDifferentiated="false">
        <sellerName>Americanas.com</sellerName>
        <thumbnail url="http://imagem.buscape.com.br/vitrine/logo81.gif"/>
        <links>
            <link url="http://www.americanas.com.br" type="seller"/>
        </links>
        <contacts>
            <contact value="4003-4848" label="Atendimento"/>
            <contact value="0300-7893200" label="Televendas"/>
            <contact value="4003-1000" label="Televendas"/>
        </contacts>
        <rating>
            <userAverageRating>
                <numComments>10773</numComments>
                <rating>0.0</rating>
            </userAverageRating>
            <eBitRating>
                <numComments>10773</numComments>
                <rating>Diamante</rating>
                <ratingNew>e-bit Excelente</ratingNew>
                <ratingId>40</ratingId>
                <ebitId>568</ebitId>
            </eBitRating>
        </rating>
    </seller>
</offer>
<offer categoryId="10" id="120912411">
    <offerName>Caixa de Som Portátil Azul SSMN 101 - HoMedics ( 110969373 )</offerName>
    <offerShortName>Caixa De Som </offerShortName>
    <links>
        <link url="http://links.lomadee.com/ls/of/Y249N01WSTttZHNyYz0zMzU4MzI4NTtlbXBfaWQ9ODE7bWRhcHA9NTc5ODtwcm9kX2lkPTEyMDkxMjQxMTt4bGs9aHR0cDovL3d3dy5hbWVyaWNhbmFzLmNvbS5ici9wcm9kdXRvLzExMDk2OTM3My9jYWl4YS1kZS1zb20tcG9ydGF0aWwtYXp1bC1zc21uLTEwMS1ob21lZGljcz9lcGFyPWJ1c2NhcGUmb3BuPVlZTktaQjtjb3VudHJ5PUJSO2h0PWQ1YzNlYzRkNjY2MTgzZTA1NmVlMzdhYmJmZDA4Mzc2O21kZHRuPTA-.html" type="offer"/>
    </links>
    <thumbnail url="http://thumbs.buscape.com.br/T100x100/__2.81-734fa1b.jpg"/>
    <price>
        <currency abbreviation="BRL"/>
        <value>44.91</value>
    </price>
    <seller id="81" isTrustedStore="true" pagamentoDigital="false" advertiserId="0" oneClickBuy="false" oneClickBuyValue="0" cpcDifferentiated="false">
        <sellerName>Americanas.com</sellerName>
        <thumbnail url="http://imagem.buscape.com.br/vitrine/logo81.gif"/>
        <links>
            <link url="http://www.americanas.com.br" type="seller"/>
        </links>
        <contacts>
            <contact value="4003-4848" label="Atendimento"/>
            <contact value="0300-7893200" label="Televendas"/>
            <contact value="4003-1000" label="Televendas"/>
        </contacts>
        <rating>
            <userAverageRating>
                <numComments>10773</numComments>
                <rating>0.0</rating>
            </userAverageRating>
            <eBitRating>
                <numComments>10773</numComments>
                <rating>Diamante</rating>
                <ratingNew>e-bit Excelente</ratingNew>
                <ratingId>40</ratingId>
                <ebitId>568</ebitId>
            </eBitRating>
        </rating>
    </seller>
</offer>
						
How to run in random order?
– Jorge B.
shuffle($xml->links)before thefor.– Diego Souza
But in this he will randomize only the link and not divide it whole, correct? And I didn’t understand how you apply.
– Rodrigo B. Silva
sorry... So this whole block generates a div with a product inside, name, image, link, etc... this is a product and in xml there are many others and I want these products to be in random order and not just use the sequence that is in xml. ?
– Rodrigo B. Silva
I could understand that. And what I told you you tested ?
– Diego Souza
I did but the only thing he did was leave random links, I need the content inside the div to be from the same product. I will add XML upstairs with only 2 products.
– Rodrigo B. Silva
Great. Add that to see what it’s all about.
– Diego Souza