0
Good afternoon guys, I’m having a doubt would have as soon as I clicked on the button it called a function in js and another in php?
I have a problem I want a variable in case $name receives the value you type in an input and when you click on the button do the check with db and return on the same page the results,
<script type="text/javascript">
function fnome() {
$nome = document.getElementById('nome').value;
}
</script>
<button onclick="fnome()">Pega</button>
<?php
$sql = mysql_query("SELECT * FROM pedidos WHERE nome LIKE '%".$nome."%'");
$row = mysql_num_rows($sql);
if ($row > 0) {
while ( $linha = mysql_fetch_array($sql)){
$id = $linha['id'];
$nome = $linha['nome'];
$pedido = $linha['pedido'];
$valor = $linha['valor'];
echo "<br><br>ID: ". @$id;
echo "<br><strong>Nome: </strong>". @$nome;
echo "<br>Pedido: ". @$pedido;
echo "<br>Valor: ". @$valor ;
}
}
else {
echo "Desculpe nenhum pedido foi encontrado!";
}
?>
I passed to the php file, but at the time of ajax I am very difficult, this file is returning in echo, I do not know if it is possible to return the values in a grid or table, from what I understood in ajax, have to pass the values to an id in html, as it would be in a table or grid the values returned?
– Samuel Arna
Ajax sends an object, then you put what you want on that object, and you read it in PHP as you wish too, rs, I only recommend decoding it from JSON to PHP with some native PHP function that should exist.
– Raryson Pereira Rost