tags:

views:

651

answers:

1

Hi there i'm trying to check if a string match one of the fields in a certain column in a table for this i need to get all the rows from result object i'm using php 5.2.x so can't use fetch_row_all method instead i'm tring to build a new array that will hold all rows here is my code:

$sql = new mysqli($config['host'],$config['user'],$config['pass'],$config['db_name']);
        if (mysqli_connect_errno())
        {
            printf("Connect failed: %s\n", mysqli_connect_error());
            exit();
        }
        $query = "SELECT domain FROM services";
        $result = $sql->query($query);           
        while($row = $result->fetch_row());
        {
            $rows[]=$row;
        }
        $result->close();
        $sql->close();
        return $rows;

$rows suppose to be the new array that contain all rows but instead i get an empty array any ideas why this is happening?

+1  A: 

You had a slight syntax problem, namely an errant semi-colon.

while($row = $result->fetch_row());

Notice the semi-colon at the end? It means the block following wasn't executed in a loop. Get rid of that and it should work.

Also, you may want to check that the query actually works:

$sql = new mysqli($config['host'], $config['user'], $config['pass'], $config['db_name']);
if (mysqli_connect_errno()) {
  printf("Connect failed: %s\n", mysqli_connect_error());
  exit;
}
$query = "SELECT domain FROM services";
$result = $sql->query($query);     
if (!$result) {
  printf("Query failed: %s\n", $mysqli->error);
  exit;
}      
while($row = $result->fetch_row()) {
  $rows[]=$row;
}
$result->close();
$sql->close();
return $rows;
cletus
oh... how embarrassing i shouldn't work that late (it's 2:30 am here:)THANKS cletus this worked out :)
Yaniv