Jump to content

Populating a select list from a database


-Karl-

Recommended Posts

Alright, so I have my select list

		<select style="width: 345px; vertical-align: top; height: 143px;" id="background" name="members" size="7">
					<option value="username1">username1</option>
					<option value="username2">username2</option>
				</select>

 

The problem is the options are proportional to the database information. Am I correct in thinking I can do it like this?

 

<select style="width: 345px; vertical-align: top; height: 143px;" id="background" name="members" size="7">
<?php
$i = 0;
while($result_ar = mysql_fetch_assoc($query)){
echo "<option value='{$result_ar['username']}'>{$result_ar['username']}</option><?php $i+=1; ?>";
}

?>
</select>

 

Or something similar?

I have:

		<select style="width: 200px; vertical-align: top; height: 143px;" id="background" name="members" size="7" onchange="javascript:changeSampleColor(this.value);">
HTML;
		$url = $arr['url'];
		$clan = mysql_query("SELECT * FROM `clan` WHERE `url` = '$url'");
		$editmembers = mysql_query("SELECT * FROM `members` WHERE `clanurl` = '$clan'");
		$i = 0;
		while($result_ar = mysql_fetch_assoc($editmembers)){
		echo "<option value='{$result_ar['username']}'>{$result_ar['username']}</option>";
		$i+=1;
		}
echo <<<HTML

				</select>

However, the $url won't work, and the select list isn't echoing any data. I just can't figure out why.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.