Hi all,
I am still learning about using these arrays! ?
I am using the code below to create an array that I use in a select box.
So that it looks nicer I want to have 2 elements in the array – one that will be
the stored variable and the other that will be displayed in the select box.
Here is my code (so far):
[code=php]
$sql = “SELECT DISTINCT account_name,SO_num FROM $client_table
WHERE account_type =’S_ORD’ ORDER BY ‘account_name,SO_num,prod'”;
$result = mysql_query($sql)
or die(“Couldn’t execute MAKE CUST LIST query.”);
while($row = mysql_fetch_assoc($result)) {
$optionsAll[] = “{$row[account_name]}/-/{$row[SO_num]}”;
} // end while
$options = array_unique($optionsAll);
// some HTML table formating goes here//
<select name=’sal_ord’>
<?php
foreach($options as $value)
{
echo “<option value=’$value’>$value</option>n”;
} // end for loop
Now I guess that the created array “$options” contains just the counter ( 0 – whatever ) and one element
which is $row[account_name] /-/ $row[SO_num]
For display purposes I want another element in the array that will be:
” $row[account_name] – $row[SO_num]”.
If I want to use this element in my SELECT box using the var name $disp like this:
[code=php]
<select name=’sal_ord’>
<?php
foreach($options as $value)
{
echo “<option value=’$value’>$disp</option>n”;
} // end for loop
How do I create this extra element in the while loop and
how do I use it in the “foreach($options as $value) ” statement ???
Thanks for your help !
David.