I can not show the result of a query

0

I can not show the result of the query, I want to show it in a json object.

global $mysqli;
$stmt = $mysqli->prepare("select CONCAT(usuarios.apellidop,' ',usuarios.apellidom,' ',usuarios.nombres) as nombre,
    usuarios.foto,usuarios.user,asistencia.asistio from asistencia
    inner join usuarios on usuarios.user = asistencia.codigoest
    where asistencia.codigoasig = '".$s."' and asistencia.fecha= '".$fecha."' order by usuarios.apellidop ");
$stmt->execute();

Before I used:

$sql="select CONCAT(usuarios.apellidop,' ',usuarios.apellidom,' ',usuarios.nombres) as nombre,
    usuarios.foto,usuarios.user,asistencia.asistio from asistencia
    inner join usuarios on usuarios.user = asistencia.codigoest
    where asistencia.codigoasig = '$s' and asistencia.fecha= '$fecha' order by usuarios.apellidop ";
$query=mysqli_query($con,$sql)or die(mysqli_error($con));
if(mysqli_num_rows($query)){
   while($row=mysqli_fetch_array($query)){
   $data[] = array('nombre'=>$row['nombre'],'foto'=>base64_encode($row['foto']),'codigo'=>$row['user'],'asistio'=>$row['asistio']);
}
echo json_encode($data);
}
    
asked by Rodolfo Gav 28.05.2017 в 08:01
source

1 answer

0

This is a way to show the data:

$conn = new PDO($this->dsn,$this->user,$this->pass);
$consulta = $conn->query($sql);
$consulta->fetchAll(); // muestra los datos 

If you notice, I'm using fetchAll (), which I associate with the PDO connection, where I made the query.

Being a PDO search, you have to know that you have to use the questions.

$stmt = $mysqli->prepare("select CONCAT(usuarios.apellidop,' ',usuarios.apellidom,' ',usuarios.nombres) as nombre,
    usuarios.foto,usuarios.user,asistencia.asistio from asistencia
    inner join usuarios on usuarios.user = asistencia.codigoest
    where asistencia.codigoasig = '".?."' and asistencia.fecha= ? order by usuarios.apellidop ");

As in the following example

/* Ejecutar una sentencia preparada vinculando varialbes de PHP */
$calorías = 150;
$color = 'red';
$gsent = $gbd->prepare('SELECT name, colour, calories
    FROM fruit
    WHERE calories < ? AND colour = ?');
$gsent->bindValue(1, $calorías, PDO::PARAM_INT);
$gsent->bindValue(2, $color, PDO::PARAM_STR);
$gsent->execute();

More info on the php pdo documentation

    
answered by 28.05.2017 в 11:56