Binary Expressions

2006-6-5

PHP – Populate HTML Select Element

Filed under: — Adam @ 2:00 pm

There is many ways to populate vales into a HTML select element. Here is one example I’ve come up with.

PHP Code Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<select size="1" name="szFooBar[]" multiple="multiple">
< ?php
$i=0;
while($obResults = mysql_fetch_row($saResults))
{
    if ($_POST['szFooBar'] == $obResults[0])
    { $szSelectedValue[$i] = " selected=\"selected\""; }
    else { $szSelectedValue[$i] = ""; }
 
    printf("<option value=\"%s\"%s>%s\n",$obResults[0], $szSelectedValue[$i], $obResults[1]);
    $i++;
}
?>							
</select>

One Response to “PHP – Populate HTML Select Element”

  1. Hello, just thought you’d be interested to know that I have saved your site to my bookmarks because of your great blog layout (LOL). With that said, seriously, I believe your blog has one of the cleanest design I’ve seen yet. It really makes your blog post easier to read.

Leave a Reply

Take back your mailbox - CAUCE.org

Powered By Wordpress PHP: Hypertext Preprocessor MySQL Powered Download Juice, the cross-platform podcast receiver
Proud To Be Canadian Get Firefox Valid XHTML Valid CSS
<NO>OOXML Logo


24 queries. 0.493 seconds.
Copyright © 2004 - 2005 by Adam Douglas