3
I’m setting up a search page where on the HTML page a search button when clicked calls a Javascript function that passes the typed content to a php page. This PHP page must connect to the database, search for what was typed and return some values in a table, this table must be returned to the html page (through javascript), and shown in a div with id="Resultado"
but he’s making a mistake:
Warning: mysqli_query(): (HY000/2008): Mysql client Ran out of memory in /home/irbpe586/public_html/irbapp/testesearch/search.php on line 7 An error occurred in the query!
Please if anyone can help me I’m so grateful.
Javascript within the html:
<script type="text/javascript">
$("#pesquisa_1").click(function() {
if($(this).val() != ""){
var rua = $('#pesquisa_rapida').val();
var urlmanual = "pesquisa.php";
$.post(urlmanual, {"pesquisa_rapida" : pesquisa_rapida} ,function(result) {
var div = document.getElementById("#Resultado");
div.innerHTML = result;
alert (result);
});
}});
</script>
HTML:
<input type="text" id="pesquisa_rapida" name="pesquisa_rapida" class="form-control item-formulario" placeholder="Pesquisa rápida..."/>
<button type="submit" id="pesquisa_1" name="opcao" value="1" class="btn botao1 item-formulario"><span class="glyphicon glyphicon-search"></span></button>
PHP:
<?php
if(isset($_POST['pesquisa_rapida'])){
$input = $_POST['pesquisa_rapida'];
@$con = mysqli_connect("host.com.br", "user", "******", "database");
if($con){
$query = mysqli_query($con, "SELECT * FROM `resultado` WHERE nm_candidato LIKE '%$pesquisa_rapida%'");
if($query){
if(mysqli_num_rows($query) > 0){
//tabela
echo "<table border=1 cellspacing=0 align=center>";
echo "<tr bgcolor=#c0c0c0 style=color:white>";
echo " <td> UF do Estado </td>";
echo" <td> Nome do Municipio </td>";
echo" <td> Ano das Eleicoes </td>";
echo" <td> Nome do Candidato </td>";
echo" <td> Nome do Candidato na Urna </td>";
echo "</tr>";
while($result = mysqli_fetch_assoc($query)){
echo "<tr>";
echo "<td>"; echo 'UF do Estado: '.$result['sg_uf'].'<br />'; echo "</td>";
echo "<td>"; echo 'Nome do Municipio: '.$result['nm_municipio'].'<br />'; echo "</td>";
echo "<td>"; echo 'Ano das Eleicoes: '.$result['dt_ano'].'<br />'; echo "</td>";
echo "<td>"; echo 'Nome do Candidato: '.$result['nm_candidato'].'<br />'; echo "</td>";
echo "<td>"; echo 'Nome do Candidato na Urna: '.$result['nm_candidatourna'].'<br />'; echo "</td>";
echo "</tr>";
}
}else{
echo 'Sem dados para essa busca!';
}
}else{
echo 'Ocorreu um erro na query!';
}
}else{
echo 'Ocorreu um erro na ligação à base de dados!';
}
}else{
echo 'Introduzir valor!';
}
?>
Try paging the results, only for testing in select put one
limit 100
– rray
Thus?
$query = mysqli_query($con, "SELECT * FROM
resultado_votacao_candidato_zona_eleicaomunicipalWHERE nm_candidato LIKE '%$pesquisa_rapida%' LIMIT 100");
– Sarah
That, the mistake is gone now?
– rray
yes, it worked out..
– Sarah
tin is q is not showing only q typed
– Sarah
it’s all coming out of the bank
– Sarah
and does not appear in html, the table is in php
– Sarah
Tip: PHP script paging
– rray
It should not be : "SELECT * FROM
resultado
WHERE nm_candidate LIKE '%$input%'" since you passed the value of $_POST["quick search"] to the $input variable? I believe you’re doing a quote like "'"– André Vicente
@That’s right, but I’ve got it, thank you.
– Sarah