tags:

views:

39

answers:

3

Hi friends why mysqli one pulling one row with foreach loop in php ? Shouldn't it fetch arrays of all rows ?

 $link = new mysqli(DB_SERVER, DB_USER,DB_PASSWORD,DB_NAME) or die('error connecting');
 $mob = query("SELECT mobile FROM members_db");
    foreach ($mob as $numbers){
        $mob_numbers = $numbers['mobile'];
        print_r($mob_numbers); exit();
    }
A: 

remove your exit(); within the loop

Haim Evgi
+1  A: 

You need to do the following

Change:

foreach ($mob as $numbers)
{
    $mob_numbers = $numbers['mobile'];
    print_r($mob_numbers); exit();
}

To

$results = array();
foreach ($mob as $numbers)
{
    $results[] = $numbers['mobile'];
}
print_r($results); exit();
RobertPitt
saved my hassle, Thank you so much.
sagarmatha
+1  A: 

You have to 'Fetch' the records one by one

$mob = query("SELECT mobile FROM members_db");
while($row = mysqli_fetch_array($link, $mob)){
    print_r($row['mobile'])
}

Also, not sure why you're calling exit() inside the loop. Doesn't make sense.

rubayeet
he use mysqli, he do not need to fetch, mysqli_query() will return a result object
Haim Evgi