I have a while cycle to show a list of data using the following code:
<?php
$stmt = $conexion->prepare("SELECT desc_unix ,cos_unix FROM unidadesx");
$stmt->execute();
$resultados = $stmt->get_result();
$contador = 0;
while ($datos = $resultados->fetch_assoc())
{
$contador = $contador + 1;
echo '<td bordercolor="#FFFFFF" align="center" width="112">' . $contador . '</td>';
echo '<td bordercolor="#FFFFFF" align="center" width="192">' . $datos["cos_unix"] . '</td>';
echo '<td bordercolor="#FFFFFF" align="center" width="596">' . $datos["desc_unix"] . '</td>';
echo "</tr>";
}
$stmt->close();
?>
This works well in PHP 5.4.0. When passed to PHP 5.3.0 it shows nothing.
-
The first thing I did was to test the value of
$resultados
, since up to where this sentence was the HTML was displayed, I had to change fromget_result();
tostore_result();
to show the whole document. -
The second thing was that it generated the columns but the data did not think the problem was in
fetch_assoc()
and change it bymysql_fetch_array
. -
Now it shows all the HTML content but not the data, that is, it leaves column 1, 2, 3 but empty.
Here is the final code:
<?php
$stmt = $conexion->prepare("SELECT desc_unix ,cos_unix FROM unidadesx");
$stmt->execute();
$resultados = $stmt->store_result();
$contador = 0;
while ($datos = mysqli_fetch_array($resultados,MYSQL_ASSOC))
{
$contador = $contador + 1;
echo '<td bordercolor="#FFFFFF" align="center" width="112">' . $contador . '</td>';
echo '<td bordercolor="#FFFFFF" align="center" width="192">' . $datos["cos_unix"]. '</td>';
echo '<td bordercolor="#FFFFFF" align="center" width="596">' . $datos["desc_unix"]. '</td>';
echo "</tr>";
}
$stmt->close();
?>
How can I make this cycle work in PHP 5.3?