Knowing when I click on a div the value in the PHP table

0

I have the following problem. I want to get when I click a div, a value of an array. In other words, I make a query to my table, to get the value. The problem is that I always have the first value. Here is the function that does the query

function select($dir, $base, $i){                       
    //for($y=$arraylenght; $y>0; $y--){ 
    $array_resultados = array(); //array    

    $arraylenght =15;
    for($y=1; $y<=$arraylenght; $y++){ 
        $base_hndl  =   new SQLite3($dir.$base);                    
        $requete    =   "SELECT id, title, start, end, description, jour, mois, annee, date 
            FROM \"event\" 
            WHERE jour=\"$i\"
            AND id=$y";

        $resultat   =   $base_hndl->query($requete);     
        $affiche    =   $resultat->fetchArray();
        array_push($array_resultados, $affiche); //insert in array

    }

    return $array_resultados;
}

And the div

if($day==$i)
{   
    $array_resultados = array(); //array    

    //function pour montrer les evenements dans le array        
    $array_resultados=select($dir, $base, $i);

    $titles = ""; //variable inicialize
    foreach($array_resultados as $key =>$value){
        $titles .= "<div class=dois onclick='popup(\"_popup_cal.php?jour=$i&moisEcris=$months[$moisaff]&annee=$year&mois=$month&txttitle=$txttitle&txtstart=$txtstart&txtend=$txtend&txtdescription=$txtdescription&maj=$maj&clean=1&teste=$txttitle\",400,300)';>
                                ".$value['title'].
                                "</div>"; //save in variable value  
    }
}

The problem is that I always have the same div to be generated. I can not distinguish where I click.

    
asked by anonymous 06.11.2014 / 15:57

1 answer

1

Why do not you try using javascript / jquery and $ .ajax to make the request? Here's a basic example.

js

$('#div-alvo').on('click' , function(){
    $.ajax({
            url : <caminho do arquivo.php> ,
            dataType : 'json' ,
            data : <variavel que deseja enviar> ,
            success : function(){} ,//caso tenha sucesso, executa as linhas abaixo
            error : function(jqXHR, textStatus, errorThrown){ 
            //Caso tenha erro, mostre no console o erro
               console.log(errorThrown);    
            }
});
    
06.11.2014 / 17:20