Forum Moderators: open

Message Too Old, No Replies

dynamic menu problem with js, php and mySQL

         

bagheera

9:11 pm on Nov 27, 2004 (gmt 0)

10+ Year Member



I have maybe a simple problem. I would like a rollover menu that would work like:
Tools
> drillers
> hammers
> screws
etc.
...

But I would like the menu to be filled up dynamically (as I enter my DB table for the Tools) so I do not need to update the html page.

How can I get the tools types to be reflected in the menu?

Do I need to call some js while looping through or...?

Im not good at js.

Any adivce would make my day better,
thanks

Serap

StupidScript

7:14 pm on Nov 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi bagheera,

You indicate in your thread title that you have access to PHP/MySQL ... so here's how to do it using those:

<!-- begin drop-down menu code in HTML -->
<select name="tool_list">
<option value=NULL />Select:
<?
# connect to the db server
$get_db=mysql_connect("servername","username","password");
# set up query
# I'm making assumptions about your table structures ...
$get_tools=mysql_db_query("dbname","select * from tools order by tool_name");
# run query
while($row=mysql_fetch_array($get_tools)) {
# print a drop-down item for each tool in the db
echo '<option value='.$row["id"].' />'.$row["tool_name"].'\n';
}
# close db connection when done
mysql_close($get_db);
?>
<!-- finish drop-down menu code in HTML -->
</select>

That's the basic idea. I've used a form to illustrate the technique of using two database fields (id and tool_name), but you can do it without the form just as easily. Check the PHP forum for more. Best of luck!