Jump to content

Archived

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

skatermike21988

Display mysql result in a drop down box

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[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...

Share this post


Link to post
Share on other sites

×

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.