jj1103
asked on
Fill in a PHP array with MySQL Data
I have an array that I'd like to fill in with data from a MySQL Database. It works great when I enter the data inside the ' ' but when I fetch the data from the database using $row = mysql_fetch_array() it breaks.
I guess I'm trying to place an array inside an array. Is there a better way to autofill the $fields array() with data from the MySQL Database?
//mysql_connect info here//
$result = mysql_query("SELECT * FROM employees WHERE accesscode='" . $accesscode . "'");
while ($row = mysql_fetch_array($result)) {
$LastName = $row['LastName'];
$fields = array(
'txtLastName' => $LastName,
'txtFirstName' => 'TEST',
'txtMiddleName' => 'TEST',
...
<?php
}
mysql_close($conn);
?>
I guess I'm trying to place an array inside an array. Is there a better way to autofill the $fields array() with data from the MySQL Database?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
After playing around with it I decided to use the form page that collects all the database data and then sends it to another page where I can collect it into an array and it worked well.
Thank-you for your assistance in helping me think outside the code :)
Thank-you for your assistance in helping me think outside the code :)
ASKER
I tied both your recommendations. It comes up with blank field 0. These are specific fields I need to name (i.e. txtLastName) and not use a relative array.
Open in new window
The 'lastnamefromdatabase' should be something like echo $row['LastName'];