I'm getting values from an associative array
$datos = "";
$array = array(1, 2, 3, 4);
foreach ($array as $valor => $dato) {
$datos = $datos . $dato . ",";
}
$app = rtrim($datos, ",");
echo $app;
Result: 1,2,3,4
Now it's strange I do not understand what is happening in a procedure in object-oriented style in MySQLi it only shows me one result and the rest ignores them.
$stmt = $con->prepare("SELECT id, notice, tag FROM news WHERE id in (?)");
$stmt->bind_param('i',$app);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id, $notice, $tag);
while ($stmt->fetch()) {
echo '<div class="content-notice">
<h1>'.$notice.'</h1>
<span>'.$tag.'</span>
</div>';
}
I tried changing the integer (i)
by string
(s)
but it gives the same result it only shows one result ...
On the other hand, in a different procedure without object orientation there if you print the 4 results.
$sql = "SELECT * FROM news WHERE id in ({$app})";
$query = mysqli_query($con, $sql);
while ($row = mysqli_fetch_assoc($query)){
echo '<h1>'.$row['notice'].'</h1>';
}
Can you explain what is happening?