Jump to content


Photo

Display mysql result in a drop down box


  • Please log in to reply
8 replies to this topic

#1 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 05 September 2006 - 05:21 AM

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

#2 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 05 September 2006 - 06:00 AM

Here is my 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>";
}
I have tried many things and so far it just display's the drop box but with no data.

#3 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 05 September 2006 - 06:41 AM

Try this:
<?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>";
?>


#4 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 05 September 2006 - 07:53 AM

nope no luck :(

#5 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 05 September 2006 - 08:12 AM

you probably have an SQL error or return error
redo you're $result line to look like this

$result = mysql_query("SELECT `font_name` FROM `fonts`") or die(mysql_error());
you could have mispelled your column name in the Database or somthing like that

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#6 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 05 September 2006 - 08:35 AM

no errors are coming up

#7 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 05 September 2006 - 08:52 AM

try redoing this line to look like this then....that's the only last thing I can think of
echo "<option value='" . $row['font_name'] . "'>" . $row['font_name'] . "</option>";
or

echo "<option value='{$row['font_name']}'>{$row['font_name']}</option>";

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

$row['font_name']


btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#8 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 05 September 2006 - 09:55 AM

no errors are coming up

You might have to switch on your errors with something like error_reporting(15); or something...

#9 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 05 September 2006 - 02:19 PM

switch on your errors


good point...

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users