Reputation: 496
How can I easily add data from MySQL to a multidimensional array in PHP? I am making a search box and I want to store the first name, and the last name in the array.
Why does not this work.
$result = mysqli_query($db, $sql) or die(mysqli_error());
$data = array();
while ($row = mysqli_fetch_array($result)) {
$data[$row['primary']] = $row['firstname'], $row['lastname'];
}
Upvotes: 1
Views: 97
Reputation: 496
$data[$row['primary']] = array($row['firstname'], $row['lastname']);
Upvotes: 1