MySQL Forums
Forum List  »  Spanish

No arroja todos los datos solo cuando existe más de 1.
Posted by: Ric Rey
Date: February 20, 2021 01:57PM

Hola tengo mi pequeño script php que da como repuesta los datos de una base de datos... pero tengo un problema solo da repuesta cuando existen más de 2 datos, si solo hay 1 no muestra nada...

aquí mi código :(

<?php
$nombre_Cliente = NULL;
$buscarPor = trim(filter_input(INPUT_POST,'Criterio', FILTER_SANITIZE_STRING));
$where = trim(strtolower(filter_input(INPUT_POST, 'itBuscar', FILTER_SANITIZE_STRING)));
$buscar = true;
if (empty($where))
{
$buscar = false;
}
if ($buscarPor === 'Email')
{
if(!filter_var($where, FILTER_VALIDATE_EMAIL))
{
$buscar = false;
}
}
$sq1 = "SELECT os.idOs, cli.nomecliente, os.datainicial, os.datafinal, os.status, os.observacoes, os.laudotecnico
FROM clientes cli
INNER JOIN os ON os.clientes_id = cli.idClientes";
if ($buscar)
{
$datoBuscar = "'".$where."'";
if ($buscarPor === 'Documento')
{
$query = $sq1. " WHERE cli.documento = $datoBuscar";
}
else
{
$query = $sq1. " WHERE cli.email = $datoBuscar";
}
$cn = new mysqli('localhost', 'root', '', 'stecnico') or exit( mysqli_connect_error() );
mysqli_set_charset($cn,"utf8");
$rs = $cn->query($query) or exit( $cn->error );
$nombre_Cliente = $rs->fetch_assoc()['nomecliente'];
$vecresultado = array();
while ($fila = $rs->fetch_row())
{
array_push($vecresultado, $fila);
}
mysqli_free_result($rs);
mysqli_close($cn);
}
else
{
header("Location: /stecnico/consultaros/index.php?Error=s");
}
?>

Options: ReplyQuote


Subject
Views
Written By
Posted
No arroja todos los datos solo cuando existe más de 1.
369
February 20, 2021 01:57PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.