Page 1 of 1

Insert from database into multidimensional array

Posted: Wed Dec 23, 2009 5:45 am
by klevis miho
I am not be able to insert data from mysql database into this array:

Code: Select all

$sql = "SELECT name, surname, age, birthday, country FROM persons";
$query = mysql_query($sql) or die(mysql_error());

Code: Select all

        while($row = mysql_fetch_assoc($query)) {
        
            $arrayTest = array(
                         array (
                            "name" => $row['name'],
                            "surname" => $row['surname'],
                            "age" => $row['age'],
                            "birthday" => $row['birthday'],
                            "country" => $row['country'],
                            )
                        ); 
        }
What am I doing wrong?

Re: Insert from database into multidimensional array

Posted: Wed Dec 23, 2009 6:34 am
by pbs
You can try this, you will get 2 dimensional array.

Code: Select all

 
 while($row = mysql_fetch_assoc($query)) {
    $data[] = $row;
  }
 
echo "<pre>";
print_r($data);
echo "</pre>";
 

Re: Insert from database into multidimensional array

Posted: Wed Dec 23, 2009 6:36 am
by klevis miho
Thnx I solved it myself lol, just as you said here :)