Stuck on creating dynamic 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
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Stuck on creating dynamic array

Post by micknc »

I have the following code:

Code: Select all

 
$status_codes = array(
'1'=>'Filed ',
'2' => 'Not Assigned',
'3' => 'Not Assigned',
'4' => 'Not Assigned',
'5' => 'Not Assigned',
'6' => 'Not Assigned',
'7' => 'Not Assigned',
'8' => 'Not Assigned',
'9' => 'Not Assigned',
'10' => 'Batched',
'11' => 'At Pulling Station',
'12' => 'ON HOLD PENDING ACTION',
'13' => 'Sorting',
'14' => 'Batched for Mon',
'15' => 'Batched for Tues',
'16' => 'Batched for Wed',
'17' => 'Batched for Thurs',
'18' => 'Being Pulled',
'19' => 'Delayed',
'20' => 'Order Shipped',
'21' => 'Canceled',
'25' => 'Invoiced',
);
 
 
I would really like to generate this from a mysql table. I know this easy but so far I haven't been able to recreate it.
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Re: Stuck on creating dynamic array

Post by micknc »

I should have included what I have now:

Code: Select all

 
$status = "SELECT * FROM status";
$status_result = mysql_query($status) or die('Query failed: ' . mysql_error());
while($status_row = mysql_fetch_array($status_result, MYSQL_ASSOC)){
$status_codes = array ($status_row['status'] => $status_row['descrip']);
};
 
With this I am getting an error:
Undefined index: 20

20 is the status and it should substitute the descrip for 20

Anyone see anything?
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Re: Stuck on creating dynamic array

Post by micknc »

I finally got it to work... I am not exactly sure what all is going on here but I found an example and bent it to use with mine.

Code: Select all

 
$status_codes = array();
$status = "SELECT * FROM status";
$status_result = mysql_query($status) or die('Query failed: ' . mysql_error());
while($status_row = mysql_fetch_array($status_result, MYSQL_ASSOC)){
$status_codes[$status_row['status']] = $status_row['descrip'];
};
 
Post Reply