Page 1 of 1

Stuck on creating dynamic array

Posted: Wed Mar 19, 2008 9:06 pm
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.

Re: Stuck on creating dynamic array

Posted: Wed Mar 19, 2008 9:20 pm
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?

Re: Stuck on creating dynamic array

Posted: Wed Mar 19, 2008 10:10 pm
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'];
};