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;
}