thanks John,
i was thinking along similar lines.
that should work well.

-----Original Message-----
From: John W. Holmes [mailto:[EMAIL PROTECTED]]
Sent: Friday, 29 November 2002 4:08 PM
To: 'Gavin Amm'; 'Php-Db (E-mail)'
Subject: RE: [PHP-DB] foreach loop from MySQL select query to HTML
select list

> hmm, interesting to know the mysql_fetch_array() by default returns an
> array
> that's associative AND numeric - very useful to know & something i'll
> to look into more, thanks Jason.
> Thanks also John, puting curley braces around the variables is a
> lesson - works wonderfully - cheers.
> i do have one more problem though, i need to run the loop a 2nd time
> in the page in exactly the same way, but nothing is returned.
> i just copied & pasted the code from one section of the page to the
> do i need to reset one of the vaiables?
> <select name="dept">
>   <option>-select-</option>
>   <?PHP
>   while($row = mysql_fetch_array($result_dept)){
>     echo "<option value=\"{$row['dept']}\">{$row['dept']}</option>\n";
>   }
>   ?>
> </select>

Put the options into a variable and just echo it out where you need it.

$options = "<option>-select-</option>\n";
while($row = mysql_fetch_row($result))
{ $options .= "<option value=\"{$row[0]}\">{$row[0]}</option>\n"; }

And wherever you need a select statement, just 

<select name="dept">

---John Holmes...

PHP Database Mailing List (
To unsubscribe, visit:

This e-mail and any attachments are intended solely for the named addressee,
are confidential and may contain legally privileged information. 

The copying or distribution of them or of any information they contain, by
anyone other than the addressee, is prohibited. If you received this e-mail
in error, please notify us immediately by return e-mail or telephone +61 2
9413 2944 and destroy the original message. Thank you. 

As Email is subject to viruses we advise that all Emails and any attachments
should be scanned by an up to-date Anti Virus programme automatically by
your system. It is the responsibility of the recipient to ensure that all
Emails and any attachments are cleared of Viruses before opening. KSG can
not accept any responsibility for viruses that maybe contained here in.
Please advise KSG by return Email if you believe any Email sent by our
system may contain a virus. It should be noted that most Anti Virus
programmes can not scan encrypted file attachments (example - documents
saved with a password). Thus extra care should be taken when opening these

Liability limited by the Accountants Scheme, approved under the Professional
Standards Act 1994 (NSW). 

Level 4 
54 Neridah Street                PO Box 1290 
CHATSWOOD   NSW   2067           CHATSWOOD   NSW   2057 

Ph: +61 2 9413 2944              Fax: +61 2 9413 9901

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to