?
Solved

How do I create Navigation via Dynamic List Menu

Posted on 2011-05-12
5
Medium Priority
?
250 Views
Last Modified: 2012-05-11
Thanks for reading this! I'm trying to create a dynamic list menu (PHP/MySQL) for site navigation. the query consists of a "title" field and a "title_url" field.  Simply put, users select a title withing the list menu, then upon selection, are sent to the corresponding url.

Any suggestions?
0
Comment
Question by:chaddcarr
  • 3
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
Erdinç Güngör Çorbacı earned 200 total points
ID: 35750726
<?php
//Get data from mysql
$qs="SELECT title,title_url FROM yourtable WHERE filters='filters' ";
$rs=mysql_query($qs);
while($row=mysql_fetch_assoc($rs)){
$options.='<option value="'.$row["title_url"].'" >'.$row["title"].'</option>';
}
?>


// any place  in HTML ...
<select id="myselect" onchange="navigate(this.value);" name="navigator">
<?=$options?>
</select>


// in Javascript Tag after select
function navigate(title_url){
   location.href=title_url;
}



I assume you have already entered title and title_url information to mysql.
And you may also need to encode and decode url data with urlencode and urldecode.
http://www.php.net/manual/en/function.urlencode.php
0
 

Author Comment

by:chaddcarr
ID: 35764619
Erdincqc - thanks for the input. It works great except I receive an error above the menu which reads "Notice: Undefined variable: options in . . ."

Consensus is to change my php.ini files however this would preclude me from receiving all error messages. Can I restructure the code you provided to mitigate this?
0
 

Assisted Solution

by:chaddcarr
chaddcarr earned 0 total points
ID: 35764680
erdincgc,

I got it! Just had to add a variable into the code as shown below. Thanks for your assistance! Most appreciated!


<?php
//Get data from mysql
$qs="SELECT title,title_url FROM yourtable WHERE filters='filters' ";
$rs=mysql_query($qs);

$options="";

while($row=mysql_fetch_assoc($rs)){
$options.='<option value="'.$row["title_url"].'" >'.$row["title"].'</option>';
}
?>


// any place  in HTML ...
<select id="myselect" onchange="navigate(this.value);" name="navigator">
<?=$options?>
</select>


// in Javascript Tag after select
function navigate(title_url){
   location.href=title_url;
}
0
 
LVL 9

Expert Comment

by:Erdinç Güngör Çorbacı
ID: 35765479
sorry for latency ... Notice: Undefined  .. like errors can easily be solved by either checking if that value is set with isset() or by defining before.
0
 

Author Closing Comment

by:chaddcarr
ID: 35800199
Had to add additional line to mitigate error message.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question