1
I’m creating a search.php
for my sisteminha, so far everything is OK, but no while
that I created to show the questions that match the searched title and their respective links, nothing appears on the page.
No SQL error or anything, just does not return any data.
I would like a better view on SQL to check if there are any errors below in the search or how to display with the while
.
<?php
require_once("php/conexao.php");
if (isset($_GET['search'])) {
$textoBusca = $_GET['search'];
$strSQL = "SELECT * FROM questoes WHERE titulo LIKE '".$textoBusca."'";
$result = mysqli_query($conexao, $strSQL);
?>
<div class="row">
<div class="col-lg-12 text-center">
<div class="page-header texto-pesquisa">
<h2>Você buscou por "<?php echo $textoBusca; ?>"</h2>
</div>
</div>
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-12 text-center">
<?php
while($row = mysqli_fetch_assoc($result)) {
$artigos = $row['titulo'];
?>
<p><?php echo $artigos; ?></p>
<?php } ?> <!-- fecha o while -->
</div>
</div>
<!-- /.row -->
<?php } ?> <!-- Fecha o IF -->
The search in the bank returns some record?
– Jeferson Assis
Barter
LIKE '".$textoBusca."'
forLIKE '%".$textoBusca."%'
and see what comes back.– henriquedpereira
Perfect, @henriquedpereira, it worked! I always have these problems with copying the SQL command to PHP and printing it right. Any tips? Rs
– Rodrigo BRF
Take a look at the documentation to better understand the use of
LIKE
= https://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like– henriquedpereira
Opa... for security, it would be better to change the way the query is mounted and use the mysqli prepare to avoid injections.
– h3nr1ke