Jump to content

Dynamic list


Yamaha32088

Recommended Posts

ME=Total newbie to php. This should be simple for most of you. Basically this is what I want. I want to create a dynamic drop down menu all of the dynamic content would be coming from a MySQL database. I need help with the coding and possibly the setup of the database. I want to create a main category after the user clicks what they want to look at another dynamic drop down menu would appear underneath it with sub categorys. Example =    FOOD(Main)>FRUIT(the rest would be sub cats)>APPLES>JOHNNY APPLESEED>GREEN. something similar to that I hope that I have been clear enough  ;D

Link to comment
Share on other sites

I don't think you'll find much help here just asking people to write code for you.

 

What you need is atleast a basic understanding of mysql commands, php commands, and a bit of javascript to accomplish what you want. It's not hard, but you should Google some mysql and php tutorials to get you started. You'll appreciate the work you put into it, anyway, as it will help you in the future. If you have specific questions, come back here and ask.

Link to comment
Share on other sites

<?php
echo("<select name=\"selection_name\">\n");
while($mysql_row = mysql_fetch_array($mysql_query) {
     echo("<option value=\"".$mysql_row['value']."\">".$mysql_row['lable']."</option>\n");
}
echo("</select>");
?>

 

You could always replace echo, with a $string .= if you want it to store in a string before output.

 

be sure to change the $mysql_row[fields] to the proper fields for you SQL table

Link to comment
Share on other sites

<?php
$sql = "SELECT * FROM table ORDER BY field";
if(!$q = mysql_query($sql))
{
	//statements
}
elseif(!mysql_num_rows($q))
{
	//statements
}
else
{
?>
<select name="select">
          <?php while($r_section = mysql_fetch_assoc($q)){ ?>
                          <option value="<?php $var=$r_section['field']; echo"$var";?>">
                                               <?php $var=$r_section['field']; echo"$var";?>
          <?php }?>
</select>
<?php
}
?>

 

Hope it helps. :)

Link to comment
Share on other sites

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.