Un ejemplo:
Código PHP:
<?php
$conexion = new mysqli('localhost', 'user', 'pass', 'db_name');
$result = $conexion->query("SELECT * FROM tabla");
if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$num_result = $result->num_rows;
for($i=0; $i<$num_result; $i++) //Tambien podemos usar un while que es mas sencillo.
{
$row = $result->fetch_object();
echo $row->campo;
}
//con while
while($row = $result->fetch_object())
{
echo $row->campo;
}
?>