Basically I'm starting with PHP by doing a small web search engine with a database that has some products.
My doubt comes, good I want to get the user to put any word I throw all the results that are related to what was entered , I did it this way:
$registros = mysqli_query($conexion, "SELECT * FROM productos WHERE
idProducto LIKE '%$keywords%' OR
Nombre LIKE '%$keywords%' OR
Marca LIKE '%$keywords%' ");
I do not know if there is any more efficient way to achieve it, I mean that if it is necessary to put it resembles what was entered with each data of my DB. Search the internet but I can not find a clear answer that will remove the doubt.
<table>
<tr>
<th>ID del producto</th>
<th>Nombre</th>
<th>Marca</th>
</tr>
if( isset( $_GET["keywords"] ) ){
$keywords = htmlspecialchars(strip_tags(trim($_GET["keywords"])));
}
if( empty($_GET["keywords"]) ){
echo "<p>Tenes que ingresar un criterio de busqueda</p>";
} else{
$conexion = mysqli_connect("localhost", "root", "", "busqueda") or die("Could not connect");
mysqli_select_db($conexion, "busqueda") or die("Todo mal");
$registros = mysqli_query($conexion, "SELECT * FROM productos WHERE
idProducto LIKE '%$keywords%' OR
Nombre LIKE '%$keywords%' OR
Marca LIKE '%$keywords%' ");
$cantidad = mysqli_num_rows($registros);
echo "<p>Se encontraron $cantidad resultado con la palabra $keywords</p>";
while( $dato = mysqli_fetch_assoc($registros) ){
?>
<tr>
<th><?php echo $dato["idProducto"]; ?></th>
<th><?php echo $dato["Nombre"]; ?></th>
<th><?php echo $dato["Marca"]; ?></th>
</tr>
<?php
}
}
?>