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

Asked

Viewed 47 times

0

I have the following problem. I want to get when I click on a div, a value of an array. That is, I query my table, to get the value. The problem is I always have the first value. Here is the function that makes 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 I always have the same div being generated. I can’t tell which one to click on.

  • you want to show the value corresponding to a <div> which is stored in a database when a click on it?

  • Okay, the problem is that a div is made whenever I add an event to the database. I want to know when I click on the div, send something to another page to know and then change that register, and not just the first. which is what’s happening.

  • make a var_dump($array_resultados) to see what is being brought from the database

  • yes inside the array I have the data.

  • $value['title'] is always printing the same value?

  • No, print the values right in the database.

Show 1 more comment

1 answer

1

Why not try using javascript/jquery and $.ajax to 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);    
            }
});

Browser other questions tagged

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