Jump to content

Display mysql result in a drop down box


skatermike21988

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/19738-display-mysql-result-in-a-drop-down-box/
Share on other sites

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.
Try this:
[code]<?php
echo "<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]
you probably have an SQL error or return error
redo 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
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-wise
they 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]

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.