Hello Daniweb.com, i hope you can help me, i am will create a dropdown navigation with php and mysql. I have some codes here, as you can look at.

My dropdown navigation works. But it will not shows under the right navigations points. As you can se here on my website. http://www.icmsdesigns.prowdesign.dk/index.php

I'm sorry at my english, is so bad. I hope you can understand me :)

find_selected_page();
echo "<div id=\"navigation\">";
echo public_navigation($sel_subject, $sel_page);
echo "</div>";

function confirm_query($result_set) {
if (!$result_set) {
die("Database query failed: " . mysql_error());
}
}

function get_all_subjects($public = true) {
global $connection;
$query = "SELECT * 
FROM icms_subjects ";
if ($public) {
$query .= "WHERE active = 1 ";
}
$query .= "ORDER BY position ASC";
$subject_set = mysql_query($query, $connection);
confirm_query($subject_set);
return $subject_set;
}

function get_pages_for_subject($subject_id, $public = true) {
global $connection;
$query = "SELECT * 
FROM icms_pages ";
$query .= "WHERE subject_id = {$subject_id} ";
if ($public) {
$query .= "AND active = 1 ";
}
$query .= "ORDER BY position ASC";
$page_set = mysql_query($query, $connection);
confirm_query($page_set);
return $page_set;
}

function get_subject_by_id($subject_id) {
global $connection;
$query = "SELECT * ";
$query .= "FROM icms_subjects ";
$query .= "WHERE id=" . $subject_id ." ";
$query .= "LIMIT 1";
$result_set = mysql_query($query, $connection);
confirm_query($result_set);
// REMEMBER:
// if no rows are returned, fetch_array will return false
if ($subject = mysql_fetch_array($result_set)) {
return $subject;
} else {
return NULL;
}
}

function get_page_by_id($page_id) {
global $connection;
$query = "SELECT * ";
$query .= "FROM icms_pages ";
$query .= "WHERE id=" . $page_id ." ";
$query .= "LIMIT 1";
$result_set = mysql_query($query, $connection);
confirm_query($result_set);
// REMEMBER:
// if no rows are returned, fetch_array will return false
if ($page = mysql_fetch_array($result_set)) {
return $page;
} else {
return NULL;
}
}

function get_default_page($subject_id) {
// Get all visible pages
$page_set = get_pages_for_subject($subject_id, true);
if ($first_page = mysql_fetch_array($page_set)) {
return $first_page;
} else {
return NULL;
}
}

function find_selected_page() {
global $sel_subject;
global $sel_page;
if (isset($_GET['subj'])) {
$sel_subject = get_subject_by_id($_GET['subj']);
$sel_page = get_default_page($sel_subject['id']);
} elseif (isset($_GET['page'])) {
$sel_subject = NULL;
$sel_page = get_page_by_id($_GET['page']);
} else {
$sel_subject = NULL;
$sel_page = NULL;
}
}

function navigation($sel_subject, $sel_page, $public = false) {
$output = "<ul class=\"subjects\">";
$subject_set = get_all_subjects($public);
while ($subject = mysql_fetch_array($subject_set)) {
$output .= "<li";
if ($subject["id"] == $sel_subject['id']) { $output .= " class=\"selected\""; }
$output .= "><a href=\"edit_subject.php?subj=" . urlencode($subject["id"]) . 
"\">{$subject["subject_name"]}</a></li>";
$page_set = get_pages_for_subject($subject["id"], $public);
$output .= "<ul class=\"pages\">";
while ($page = mysql_fetch_array($page_set)) {
$output .= "<li";
if ($page["id"] == $sel_page['id']) { $output .= " class=\"selected\""; }
$output .= "><a href=\"content.php?page=" . urlencode($page["id"]) .
"\">{$page["page_name"]}</a></li>";
}
$output .= "</ul>";
}
$output .= "</ul>";
return $output;
}

function public_navigation($sel_subject, $sel_page, $public = true) { 
// $output = echo
$output = "<ul class=\"subjects\">";
$subject_set = get_all_subjects($public);
while ($subject = mysql_fetch_array($subject_set)) {
$output .= "<li class=\"subjects_li\"";
if ($subject["id"] == $sel_subject['id']) { $output .= " class=\"selected\""; }
$output .= "><a href=\"index.php?subj=" . urlencode($subject["id"]) . 
"\">{$subject["subject_name"]}</a></li>";
if ($subject["id"] == $sel_subject['id']) {	
$page_set = get_pages_for_subject($subject["id"], $public);
$output .= "<ul class=\"pages\">";
while ($page = mysql_fetch_array($page_set)) {
$output .= "<li";
if ($page["id"] == $sel_page['id']) { $output .= " class=\"selected\""; }
$output .= "><a href=\"index.php?page=" . urlencode($page["id"]) .
"\">{$page["page_name"]}</a></li>";
}
$output .= "</ul>";
}
}
$output .= "</ul>";
return $output;
}

hmmm i think your problem is more css than php

Yes maybe, here's my navgations css:

#navigation {
background:url("/_images/menu.jpg") no-repeat scroll 0 0 #222222;
height:30px;
line-height:30px;
}
#navigation a {
color: #000000;
text-decoration:none;
}
ul.subjects {
list-style:none outside none;
padding-left:0;
}
ul.pages {
background:none repeat scroll 0 0 #3A8FE9;
border-bottom:1px solid #000000;
border-left:1px solid #000000;
border-right:1px solid #000000;
float:left;
height:auto;
list-style:none outside none;
margin-left:85px;
margin-top:30px;
padding:3px;
position:absolute;
width:100px;
}
.selected {
color:#000000;
font-weight:bold;
}
.subjects_li {
float:left;
margin-left:24px;
}

Maybe you want to help me get my navigation dropdown to work.

I've tried a lot but can not get it to work.

I use one tool to change the style dynamically and find design solutions. It is called Firebug. It's a browser plug in for a Mozilla. Give it a try and you will be able to analyze working examples to get your menu work and learn new things.
(Sorry for mentioning if you are already using it)

Or you can post it to a DaniWeb web design section.

Good luck :)

Yes and thanks, i am using firebug, but i will try to post it in
DaniWeb web design section. :)

If you will take help of a jquery drop down menu plugin, it will help more.
If the structure of li and ul tags after PHP code in it will remain as it was in original , the menu should work well. Please focus on the structure of the li and ul tags.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.