I am working with mysqli in php but i'd like to know how can i retrieve data from DB with loops other than while loop?
I always use while loop to retrieve data and I've never seen anybody to use another loop to do it. is this the only way to retrieve data!!?
$select_query = "SELECT * FROM article";
if($get_from_db = $db_connection->query($select_query)){
if($get_from_db->num_rows > 0){
while($result = $get_from_db->fetch_array(MYSQLI_ASSOC)){
echo "id: " . $result['id'] . '<br>';
echo "title: " . $result['title'] . '<br>';
echo "context: " . $result['context'] . '<br>';
echo "=========================================<br>";
}
}
$get_from_db->free();
}else{
//do somthing...
}