Upload data from a query to a lightbox

Asked

Viewed 46 times

0

I am developing a system, and I have the following code that returns the results of a query:

 $Dados = $conn->getResult();

foreach ($Dados as $Linha):

  echo $Linha['event_name'];
  echo   "<a href='teste.php?id_event={$Linha['id_event']}'>Mais Informações</a><br />";

endforeach;

resulting in this:

inserir a descrição da imagem aqui

Now comes my question: How could I open a lightbox on this same page without having to reload it, getting all the information of a certain query when I click on "more info"?

being for example like this:

inserir a descrição da imagem aqui

( Of course where this show name would be the name of the show I clicked on more information, and so with all other information of the result )

Much work since now!

1 answer

1

You will need to use ajax with the creation of interactive forms for the query

for example

in the column where you generate the name, you also generate the id, or other identifier attribute within the onclick function parameter, for example

<a onclick="maisDetalhes($Linha['id_event'])">Mais Informações</a><br />

takes this id by the parameter in the javascript function

funtion(id){
var formulario = document.CreateElement("form"); //cria um elemento form
formulario.id = "form1";
formulario.action "paginadosDados.php";
formulario.method = "POST"; //ou get seilá

var input1 = document.CreateElement("input");
input1.type = text;
input1.name = "input1";
input1.value = id; //parâmentro que vc acabou de enviar 

formulario.appendChild(input1);

document.body.appendChild(formulario);

var data = $("#form1").serialize(); //pega o valor do form e envia sem recarregar

$.ajax({
        type : 'POST',
        url  : 'paginadosDados.php', // substitua
        data : data,
        dataType: 'json',
        beforeSend: function()
        {    
aqui vai a animação do carregando...
  } 
  success :  function(response){                        
            if(response.codigo == "0"){ 
           alert(response.mensagem);
  }
  }
  });
}

php only returns what you want and sends the results to that part of the sequence

example

$retorno = array('codigo' => 0, 'mensagem' => 'oi');
echo json_encode($retorno);
exit();

Obs: line J-query to make it easier, this code I wrote here in the editor so it hasn’t been tested yet

  • Felipe, sorry for my inexperience, I did not understand a thing, the part of the sucess function, and what I will put code in the php page to show on the same page ?

  • exactly, the sucess will only be executed if the action is successfully performed and returns the code 200, but that’s another matter.

Browser other questions tagged

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