Insert from database into multidimensional array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Insert from database into multidimensional array

Post 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?
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: Insert from database into multidimensional array

Post 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>";
 
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Insert from database into multidimensional array

Post by klevis miho »

Thnx I solved it myself lol, just as you said here :)
Post Reply