Error in showing data when adding a where in a MySQLi query?

0

It does not reflect the data when adding a where in a MySQLi query, if I delete the WHERE the data is reflected.

<?php
$stmt = $con->prepare("SELECT id_world,hour,date_matches,local,visitor,active FROM world WHERE active=? order by id_world ASC limit 5");
$stmt->bind_param("i",$active);

$stmt->execute();
$stmt->store_result();

if ($stmt->num_rows>0) {
  $stmt->bind_result($id_world, $hour, $date_matches, $local, $visitor, $active);
  while ($stmt->fetch()) {
    echo '<li><span>'.$hour.' '.$date_matches.'</span> '.$local.' <span class="color">Vs</span> '.$visitor.'</li>';
    }
  } else {
}
$stmt->close();
?>

You can explain me why this happens, I do not understand, the active column, it is numeric that is to say and it has numerical values in this case it is 1.

    
asked by So12 05.07.2018 в 05:58
source

1 answer

2

I would recommend that you use the direct select without having to use bind_param. In the case that active is 1 or 0 and you are interested in taking out those that have 1, it would be:

$stmt = $con->query("SELECT id_world,hour,date_matches,local,visitor,active FROM world WHERE active=1 order by id_world ASC limit 5");

In the event that even in this way you do not get any results you should check that the fields you are selecting are correct or change all the fields by a * and collect all the data.

$stmt = $con->query("SELECT * FROM world WHERE active=1 order by id_world ASC limit 5");
    
answered by 05.07.2018 / 10:03
source