So, i have been trying to display menu name from my cms database i created myself, i got it displayed perfectly but there is a really wired error, i spent many hours to discover the solution but i couldn't.

The problem is i want to display the menu name as page h1 so whenver you click on the menu name its also displaying as h1 title.

The menu name is displaying correctly, but the sub menu(pages) display N instead of the page name, i dont know where is that N is comming from.

NOTE: there is no problem with database connection or retrieving data.

any help would be appreciated!

This is my content page code:
PHP Code:
<?php include("includes/header.php"); ?>
<?php 
require_once 'includes/db_connection.php'?>
<?php 
require_once 'includes/b_functions.php'?>
<?php 
require_once 'includes/cms_constants.php'?>

<?php db_connect();?>
<?php

if (isset ( $_GET ['subj'] )) {
    
$sel_subject get_subject_by_id $_GET ['subj'] );
    
$sel_page "NULL";
} elseif (isset ( 
$_GET ['pages'] )) {
    
$sel_subject "NULL";
    
$sel_page get_page_by_id $_GET ['pages'] );
} else {
    
$sel_subject "NULL";
    
$sel_page "NULL";
}

?>

<table id="structure">
    <tr>
        <td id="navigation">
            <ul class="subjects">
                <?php
        $subject_set 
get_all_subjects();
        while (
$subject mysql_fetch_array($subject_set)) {
            echo 
"<li";
            if (
$subject["id"] == $sel_subject["id"]) { echo " class=\"selected\""; }
            echo 
"><a href=\"contents.php?subj=" urlencode($subject["id"]) . 
                
"\">{$subject["menu_name"]}</a></li>";
            
$page_set get_pages_for_subject($subject["id"]);
            echo 
"<ul class=\"pages\">";
            while (
$page mysql_fetch_array($page_set)) {
                echo 
"<li";
                if (
$page["id"] == $sel_page["id"]) { echo " class=\"selected\""; }
                echo 
"><a href=\"contents.php?pages=" urlencode($page["id"]) .
                    
"\">{$page["menu_name"]}</a></li>";
            }
            echo 
"</ul>";
        }

        
?>

        </ul>
        </td>

        <td id="page">
        <?php if (!is_null($sel_subject)) { // subject selected ?>
            <h2><?php echo $sel_subject['menu_name']; ?></h2>
        <?php } elseif (!is_null($sel_page)) { // page selected ?>
            <h2><?php echo $sel_page['menu_name']; ?></h2>
            <div class="page-content">
                <?php //echo $sel_page['content']; ?>
            </div>
        <?php } else { // nothing selected ?>
            <h2>Select a subject or page to edit</h2>
        <?php ?> </td>
    </tr>
</table>
<?php require_once 'includes/footer.php';?>
function code:

PHP Code:
<?php
function confirm_query($result_set) {
    if (! 
$result_set) {
        die ( 
"Database query failed: " mysql_error () );
    }
}
function 
get_all_subjects() {
    global 
$connection;
    
$query "SELECT *";
    
$query .= " FROM subjects";
    
$query .= " ORDER BY POSITION ASC";
    
$subject_set mysql_query $query );
    
confirm_query $subject_set );
    return 
$subject_set;
}
function 
get_pages_for_subject($subject_id) {
//    global $connection;
    
$query "SELECT * ";
    
$query .= " FROM pages";
    
$query .= " WHERE subject_id=" "{$subject_id}" ";
    
$query .= " ORDER BY POSITION ASC";
    
$page_set mysql_query $query );
    
confirm_query $page_set );
    return 
$page_set;
}
function 
get_subject_by_id($subject_id) {
    
//    global $connection;
        
$query "SELECT * ";
        
$query .= " FROM subjects ";
        
$query .= " WHERE id=" $subject_id ." ";
        
$query .= " LIMIT 1";
        
$result_set mysql_query($query);
        
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 pages ";
        
$query .= " WHERE id=" $page_id ." ";
        
$query .= " LIMIT 1";
        
$result_set mysql_query($query);
        
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;
        }
    }    
?>
DB connection function:

PHP Code:
<?php

function db_connect() {
    
// 1-connect to database -- $connection is a handler to test if database
    // connection error.
    
$connection mysql_connect DB_SERVERDB_USERDB_PASS );
    if (! 
$connection) {
        die ( 
"Database connection failed: " mysql_error () );
        
    }
    
// 2-Select the database -- $db_select is a handler to test if database
    // selection failed.
    
    
$db_select mysql_select_db DB_NAME$connection );
    if (! 
$db_select) {
        die ( 
"Database Selected failed: " mysql_error () );
        
    }
}

?>