Jump to content

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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.