-Karl- Posted April 18, 2010 Share Posted April 18, 2010 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? Link to comment https://forums.phpfreaks.com/topic/198895-populating-a-select-list-from-a-database/ Share on other sites More sharing options...
MasterACE14 Posted April 18, 2010 Share Posted April 18, 2010 try... <?php $i = 0; while($result_ar = mysql_fetch_assoc($query)){ echo "<option value='{$result_ar['username']}'>{$result_ar['username']}</option>"; $i++; } ?> Link to comment https://forums.phpfreaks.com/topic/198895-populating-a-select-list-from-a-database/#findComment-1044044 Share on other sites More sharing options...
-Karl- Posted April 18, 2010 Author Share Posted April 18, 2010 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. Link to comment https://forums.phpfreaks.com/topic/198895-populating-a-select-list-from-a-database/#findComment-1044050 Share on other sites More sharing options...
-Karl- Posted April 18, 2010 Author Share Posted April 18, 2010 This works echo "Hello $arr[url]"; But when used in a query, like so: $url = $arr[url]; $clan = mysql_query("SELECT * FROM `clan` WHERE `url` = '$url'"); It doesn't work as nothing is returned, does anyone have any ideas? Link to comment https://forums.phpfreaks.com/topic/198895-populating-a-select-list-from-a-database/#findComment-1044055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.