1. Dynamic menu and menu content show

1.At first you have to do separate the whole template.section header, content, banner, sidebar, footer.
2.Look like following index.php file

<?php
include_once('header.php');
include_once('banner.php');
include_once('content.php');
include_once('sidebar.php');
include_once('footer.php');
?>

3.create database table

db-looking

4.create crud.php

<?php class Crud { public $conn; public function __construct() { $this->conn = mysqli_connect("localhost", "root", "", "fresh");
        if (mysqli_connect()) {
            //echo "Connect Successfully";
        } else {
            die ("connection error");
            
        }
    }
    /* This is for menu showing */
    public function Menu($table){
        $query = mysqli_query($this->conn, "SELECT * FROM  $table WHERE STATUS=1");
        if(mysqli_num_rows($query)>0){
            return mysqli_fetch_all($query,MYSQLI_ASSOC);
        } else {
            echo "Menu not showing";
        }
        
    }
    
    /* This is for menu content */
    public function MenuContent($table,$id){
        $query = mysqli_query($this->conn, "SELECT * FROM  $table WHERE menu_id=$id");
        if(mysqli_num_rows($query)>0){
            return mysqli_fetch_assoc($query);
        } else{
            return false;
        }
    }

}

$obj = new Crud();

5.header.php

<?php
include_once('crud.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Demo site</title>
        <!-- SET: FAVICON -->
        <link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico" />
        <!-- END: FAVICON -->
        <!-- SET: STYLESHEET -->
        <link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
        <!-- END: STYLESHEET -->
    </head>
    <body>
        <!-- wrapper starts -->
        <div class="wrapper">
            <!-- main Starts -->
            <div class="main">
                <!-- Header Starts -->
                <div class="header">
                    <div class="logo flt_lt">
                        <h1><a href="#">Logo</a></h1>
                        <p>Your slogan goes here</p>
                    </div>
                    <div class="header_right flt_rt">
                        <ul>
                            <li><a href="#"><img src="images/twitter-logo.png" width="16" height="16" alt="twitter" class="img" /><span>twitter</span></a></li>
                            <li><a href="#"><img src="images/fb-logo.png" width="16" height="16" alt="facebook" class="img"  /><span>facebook</span></a></li>
                        </ul>
                        <div class="clear"></div>
                    </div>
                    <div class="clear"></div>
                    <div id="nav">
                        <ul>
                            <li><a href="index.php">HOME </a></li>
                            <?php
                            $headmenus = $obj->Menu("menus");
                            foreach ($headmenus as $singlemenu) {
                                extract($singlemenu);
                                //print_r($singlemenu);
                                ?>
                                <li><a href="index.php?menu_id=<?php echo $menu_id;?>"><?php echo $menu_name; ?></a></li>
                                <?php
                            }
                            ?>
                        </ul>
                        <div class="clear"></div>
                    </div>
                    <div class="clear"></div>
                </div>
                <div class="clear"></div>
                <!-- Header ends -->
                <!-- content Starts -->
                <div class="content">

6.content.php

<div class="content1">
    <div class="content1_box1 flt_lt">
        <!-- This code is for Menu content showing -->
        <?php
           if(isset($_REQUEST['menu_id'])){
               $menucontent = $obj->MenuContent("menus", $_REQUEST['menu_id']);
               //print_r($menucontent);
               echo $menucontent['menu_content'];
           }
        ?>
        
        <br/>
    </div>

Final showing like following screenshot
template-menu

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s