Gallery with PHP and Javascript not working correctly

1

I have a function in JavaScript that assembles an image gallery. I had this function all in Javascript and it worked perfectly, now I need to insert PHP so that the user can make changes to the images, and I'm passing the parameter to that function through the result of query in PHP . It should work like this: Gallery title above, and below 4 different images of query result. Below another title, and other images. The problem is that PHP is passing the same parameter to the function, doing with the function return: Gallery title and below 4 identical images (the first value of query ), another gallery title and other identical images second value of query ). How can I make the gallery load 4 different images in a gallery, not 4 identical images in different galleries?

My function in JS looks like this:

function galerias(query){
    var galeria = new Array();
        //aqui eu pego a div que armazena as galerias
        var imgs = document.querySelector("#gallery");
        var x = 1;

            imgs.innerHTML += "<div class='row'>";
            imgs.innerHTML += "<div class='eight columns'>";
            imgs.innerHTML += "<h4>Galeria "+x+"</h4>"

        //passo o valor da query para o array galeria
        for(var i = 0; i <= 3; i++){
            galeria[i] = query;
        }

        e insiro dentro da div
        for(var i = 0; i < galeria.length; i++){
            imgs.innerHTML += "<img src='img/"+query+"'class='imgs-galeria'>";
        }

        imgs.innerHTML += "</div>";
        imgs.innerHTML += "</div>";
        imgs.innerHTML += "<a class='row' href='pics.html?gal="+x+"'><div class='twelve columns link'><p>Veja mais</p></div>";
        x++;

}

My role in php:

function consultarDados($query){
    $dbResult = array();
    $conexao = mysql_connect($this->host, $this->usuario, $this->senha);
    mysql_select_db($this->banco, $conexao);
    $rs = mysql_query($query, $conexao);
        while($rows = mysql_fetch_assoc($rs)){
            array_push($dbResult, $rows);
        }
    return $dbResult;
    mysql_close($conexao);
}

I enter this php in window.onload of the page:

<?php
    foreach($galeria_1 as $result){
        echo'galerias("'.$result['nome'].'");';
    }
?>

The visual result is this:

andshouldbethis:

    
asked by anonymous 04.06.2015 / 01:47

1 answer

2

Check if this array ($ gallery_1) really has all the positions, because it looks like it only has one position.

    
04.06.2015 / 02:07