skatermike21988 Posted September 5, 2006 Share Posted September 5, 2006 Hi guys i am workin on a script that includes gd, and the user can change their font and text displayed on their profile contact, well i am wanting to be able to insert the font names into mysql and have it displayed in a drop down box, this way when i add new fonts i don't have to go and edit my whole script.I would also like for when a font is selected it will load the page that parses the gd next to the drop down and display's a preview.ALL HELP APPRECIATED Quote Link to comment https://forums.phpfreaks.com/topic/19738-display-mysql-result-in-a-drop-down-box/ Share on other sites More sharing options...
skatermike21988 Posted September 5, 2006 Author Share Posted September 5, 2006 Here is my code:[code]$sql="SELECT * FROM `fonts`";$query = mysql_query($sql);while($result=mysql_fetch_array( $query )) { echo "<select name=font><option value='$result[font_name]'>$result[font_name]</option>";}[/code]I have tried many things and so far it just display's the drop box but with no data. Quote Link to comment https://forums.phpfreaks.com/topic/19738-display-mysql-result-in-a-drop-down-box/#findComment-86185 Share on other sites More sharing options...
zq29 Posted September 5, 2006 Share Posted September 5, 2006 Try this:[code]<?phpecho "<select name='font'>";$result = mysql_query("SELECT `font_name` FROM `fonts`");while($row = mysql_fetch_assoc($result)) { echo "<option value='$row[font_name]'>$row[font_name]</option>";}echo "</select>";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19738-display-mysql-result-in-a-drop-down-box/#findComment-86196 Share on other sites More sharing options...
skatermike21988 Posted September 5, 2006 Author Share Posted September 5, 2006 nope no luck :( Quote Link to comment https://forums.phpfreaks.com/topic/19738-display-mysql-result-in-a-drop-down-box/#findComment-86218 Share on other sites More sharing options...
Zane Posted September 5, 2006 Share Posted September 5, 2006 you probably have an SQL error or return errorredo you're $result line to look like this[code]$result = mysql_query("SELECT `font_name` FROM `fonts`") or die(mysql_error());[/code]you could have mispelled your column name in the Database or somthing like that Quote Link to comment https://forums.phpfreaks.com/topic/19738-display-mysql-result-in-a-drop-down-box/#findComment-86222 Share on other sites More sharing options...
skatermike21988 Posted September 5, 2006 Author Share Posted September 5, 2006 no errors are coming up Quote Link to comment https://forums.phpfreaks.com/topic/19738-display-mysql-result-in-a-drop-down-box/#findComment-86225 Share on other sites More sharing options...
Zane Posted September 5, 2006 Share Posted September 5, 2006 try redoing this line to look like this then....that's the only last thing I can think of[code]echo "<option value='" . $row['font_name'] . "'>" . $row['font_name'] . "</option>";[/code]or[code]echo "<option value='{$row['font_name']}'>{$row['font_name']}</option>";[/code]both are the exact same thing....just depends on how YOU want it to look.....code-wisethey only real significant change I did though was to add quotes to your key[quote]$row[[size=12pt][color=red]'[/color][/size]font_name[size=12pt][color=red]'[/color][/size]][/quote] Quote Link to comment https://forums.phpfreaks.com/topic/19738-display-mysql-result-in-a-drop-down-box/#findComment-86227 Share on other sites More sharing options...
zq29 Posted September 5, 2006 Share Posted September 5, 2006 [quote author=skatermike21988 link=topic=106915.msg428261#msg428261 date=1157445330]no errors are coming up[/quote]You might have to switch on your errors with something like error_reporting(15); or something... Quote Link to comment https://forums.phpfreaks.com/topic/19738-display-mysql-result-in-a-drop-down-box/#findComment-86240 Share on other sites More sharing options...
Zane Posted September 5, 2006 Share Posted September 5, 2006 [quote]switch on your errors[/quote]good point... Quote Link to comment https://forums.phpfreaks.com/topic/19738-display-mysql-result-in-a-drop-down-box/#findComment-86379 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.