PHP - Can't Include Dynamic Nav Menu In Mvc Views
I am building a site using PHP, OOP, and an MVC framework. i am not using laravel, codeignitor, or any other framework, I am building this on my own. I am a newbie to mvc and so I am learning how it all works. I have a dynamic nav menu that populates the categories from the db. The menu/categories will populate and work fine when I view the nav page on its own, but it will not work when it is included in the index view page. What should I do to make the dynamic menu view on all the view pages that i need it to? Below is my code, any guidance would be greatly appreciated. Controller: class Behindthescenes extends Controller { public function __construct() { $this->btsModel = $this->model('mBehindthescene'); } public function index() { $data = [ 'title' => 'Admin Dashboard', ]; $this->view('/behindthescenes/index', $data); } // Get categories for nav menu public function bts_cat_nav() { $catnav = $this->btsModel->getCatsNav(); $data = [ 'catnav' => $catnav, ]; $this->view('/includes/bts_cat_nav', $data); } } Model: class mBehindthescene { private $db; public function __construct() { $this->db = new DBC; } // Get Categories for Admin Navigation public function getCatsNav() { $this->db->query('SELECT * FROM categories ORDER BY cat_name ASC'); $result = $this->db->fetchMultiple(); return $result; } } Index View: require_once APPROOT . '/views/includes/header.php'; require_once APPROOT . '/views/includes/bts_nav.php'; require_once APPROOT . '/views/includes/bts_cat_nav.php'; ?> <div class="container-fluid"> ADMIN DASHBOARD </div> Nav Menu View: <div class="container"> <div class="row"> <div class="cat_nav"> <ul> <?php foreach ($data['catnav'] as $cat): ?> <li class="nav-item"><a href="<?php echo $cat->cat_link; ?> class=" nav-link text-white p-1 mb-1 sidebar-link"><i class="<?php echo $cat->cat_fa; ?> text-light fa-lg mr-3"></i><?php echo $cat->cat_name; ?></a></li> <?php endforeach;?> </ul> </div> </div> </div>
Similar TutorialsHey Guys. I am trying to include a file. The file path gets returns from an objects method. When a run is_file() on the returned data it returns true, but does not include it!!! Can anyone please help me solve this!!
class StoreInitialization { public function loadConfigFile(){ $config_file="../store/demo/store_configuration.php"; return $config_file; }Client Code $store_config_file = $store_initialization->loadConfigFile(); require($store_config_file); Hi All, I have written the following to validate my dynamic includes, one question is i will be using sessions to control user access to certain pages. Obviously the session_start() has to go into my index.php file. Can anyone see any problems with this or my dynamic include validation code. My page varilable is populated using the mod_rewirte function in appache. <?PHP include('inc/settings.inc.php'); if(isset($_GET['page'])) { //remove slashes $page = stripslashes($_GET['page']); //rebuild the extension and file name $filename = 'lib/'.$page.'.php'; //Check to see if the file exists in lib if (file_exists($filename)) { //Dynamic Switch $allowed = array( array("test", "New Customers"), array("home", "Home Page"), ); $iffed = false; $get_section = $_GET['page']; //Create a dynamic switch to check for files being in my allowed array foreach($allowed as $rd) { if($get_section == $rd[0]) { $iffed = $rd; $content = $filename; foreach($rd as $value) { $page_title = $value; } } } if($iffed === false) { //File is not in my include list. die( "Page does not pass the validated inclusion list." ); } } else { //Page does not exist in my lib folder. die('Page does not exist, please contact the administrator.'); } } else { // If no page is requested then default home. $filename = 'lib/home.php'; $content = '1'; $page_title = 'Home'; } ?> Thanks in advance. Sam Hi, I am using php dynamic listing from database. it is working but I wanna integrate to a horizontal css menu how can i integrate my codes to any css horizantal dropdown menu. thans. here my dynamic list. <?php function sinirsiz_kategori($parent) { $sql = mysql_query("SELECT * FROM kategoriler ORDER BY id DESC"); while($row = mysql_fetch_array($sql)) { $diziler[$row['id']] = array('baslik' => $row['baslik'],'parent' => $row['parent']); } $has_childs = false; foreach($diziler as $key => $value) { if ($value['parent'] == $parent) { if ($has_childs === false){ $has_childs = true; echo "\t<ul>"; } echo "<li><a href=\"".$value['baslik'].".php\">".$value['baslik']."</a>"; sinirsiz_kategori($key); echo "</li>\n"; } } if ($has_childs === true) echo "</ul>"; } ?> <?=sinirsiz_kategori(0)?> I'm trying to make my menu dynamic for example I will have a menu with it's submenus and when the user logs on the submenu account will then be shown where it wasn't shown before the user logged on. here is my submenu.controller Code: [Select] <?php class submenus_controller extends controller{ protected $_helpers = array('form', 'html'); protected $_observers = array('seo_uris'); public $model='submenus'; public function ajax_set_submenu($submenu_id){ $submenu=$this->_model->get($submenu_id); $_SESSION['submenu']=$submenu; } } ?> and here is my default page Code: [Select] <!doctype html> <!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]--> <!--[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]--> <!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]--> <head> <title><?php echo $this->get_title();?></title> <meta name="author" content="team digitalpro"> <meta name="viewport" content="width=device-width,initial-scale=1"> <meta name = "Description" content = "<?php echo $this->get_description();?>" /> <meta name = "Keywords" content = "<?php echo $this->get_keywords(); ?>" /> <link rel="stylesheet" href="/css/style.css"> <script src="js/libs/modernizr-2.0.6.min.js"></script> </head> <body> <div id="container"> <header> <div class="inhoud"> <div id="logo"><a href="/"><img src="/img/logo.gif" width="306" height="126" border="0" /></a></div> <nav> <div class="menu"> <ul> <?php if (isset($this->_params['menus']) && is_array($this->_params['menus'])){ foreach ($this->_params['menus'] as $menu){ if (!empty($menu['submenus.page_id'])){ $uri=$this->get_uri('/pages/view/'.$menu['submenus.page_id']); }else{ $uri=$this->get_uri("/{$menu['submenus.controller']}/{$menu['submenus.action']}"); } // p($menu); ?> <li><a href="<?php echo $uri ?>" onclick="javascript:return setMenu(<?php echo $menu['id'] ?>);"><?php echo strtoupper($menu['name'])?></a></li> <?php } } ?> </ul> </div> </nav> </div> </header> <div id="hero-pic"> <div id="slogans"><img src="../img/slogans.png" width="277" height="214" /></div> <img src="../img/hero.gif" width="996" height="286" /></div> <main> <div id="left"> <div class="inhoud"> <div id="left-nav"> <ul> <?php if (isset($this->_params['submenus']) && is_array($this->_params['submenus'])){ foreach ($this->_params['submenus'] as $submenu){ if (!empty($submenu['page_id'])){ $uri=$this->get_uri('/pages/view/'.$submenu['page_id']); }else{ $uri=$this->get_uri("/{$submenu['controller']}/{$submenu['action']}"); } ?> <li<?php if ($_SESSION['submenu']['id'] == $submenu['id']){?> class="active"<?php ;} ?>> <a href="<?php echo $uri ?>" onclick="javascript:return setSubMenu(<?php echo $submenu['id'] ?>);"> <?php echo strtoupper($submenu['name'])?> </a> </li> <?php } } ?> </ul> </div> <form method="post" action=""> <input type="text" id="search" /> <input type="submit" name="button" value="GO" class="go" /> </form> <div class="sub-links"> <ul> <li><a href="#">Home</a></li> <li><a href="#">Contact us</a></li> <li><a href="#">Sitemap</a></li> <li><a href="#">Privacy policy</a></li> </ul> </div> </div> </div> <div id="right"> <div class="inhoud"> <?php echo $this->page('view') ?> </div> </div> </main> <footer> <!-- <div class="inhoud"> <ul> <li><a href="#">COMPANY </a></li> <li><a href="#">PRIVATE EQUITY </a></li> <li><a href="#">CONSULTING </a></li> <li><a href="#">INVEST </a></li> <li><a href="#">PARTNERS </a></li> <li><a href="#">NEWS</a></li> </ul> --> <p> </p> <p> </p> </div> </footer> </div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script>window.jQuery || document.write('<script src="/js/libs/jquery-1.6.2.min.js"><\/script>')</script> <script defer src="/js/plugins.js"></script> <script defer src="/js/script.js"></script> <script> window._gaq = [['_setAccount','UAXXXXXXXX1'],['_trackPageview'],['_trackPageLoadTime']]; Modernizr.load({ load: ('https:' == location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js' }); setMenu = function(menu_id){ $.ajax({ url: "/menus/ajax_set_menu/"+menu_id, type: 'POST', dataType: "html", data: { format: 'JSON', }, success: function(data) { } }); } setSubMenu = function(submenu_id){ $.ajax({ url: "/submenus/ajax_set_submenu/"+submenu_id, type: 'POST', dataType: "html", data: { format: 'JSON', }, success: function(data) { } }); } </script> <!--[if lt IE 7 ]> <script src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js"></script> <script>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})</script> <![endif]--> </body> </html> My problem is when the entries in the form are validated and some fields with incorrect entries are found the fields filled out stay on the re-load of the form, all of them except the US States drop down menu which reverts back to Alabama every time. I would like to see that the user selection stays in place even after a re-load of the form. and with my limited experience I am having an issue trying to figure this out for a school project. Any help at all would be greatly appreciated, like what variables to create/call on and where exactly I insert this code. Much appreciated. here is the display code: <?php /* Program name: exercise_4_form.inc * Description: Defines a form that collects a user's * name and mailing address. */ $rows = array( "first_name" => "First Name (optional)", "last_name" => "Last Name", "phone" => "Phone Number", "city" => "City", "state" => "State", "address" => "Address", "zip_code" => "ZIP Code", "e_mail" => "E-Mail"); $states_list = array('AL'=>"Alabama",'AK'=>"Alaska",'AZ'=>"Arizona", 'AR'=>"Arkansas",'CA'=>"California",'CO'=>"Colorado",'CT'=>"Connecticut", 'DE'=>"Delaware",'DC'=>"District Of Columbia",'FL'=>"Florida",'GA'=>"Georgia", 'HI'=>"Hawaii",'ID'=>"Idaho",'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas",'KY'=>"Kentucky",'LA'=>"Louisiana",'ME'=>"Maine", 'MD'=>"Maryland", 'MA'=>"Massachusetts",'MI'=>"Michigan",'MN'=>"Minnesota", 'MS'=>"Mississippi",'MO'=>"Missouri",'MT'=>"Montana",'NE'=>"Nebraska", 'NV'=>"Nevada",'NH'=>"New Hampshire",'NJ'=>"New Jersey",'NM'=>"New Mexico", 'NY'=>"New York",'NC'=>"North Carolina",'ND'=>"North Dakota",'OH'=>"Ohio", 'OK'=>"Oklahoma", 'OR'=>"Oregon",'PA'=>"Pennsylvania",'RI'=>"Rhode Island", 'SC'=>"South Carolina",'SD'=>"South Dakota",'TN'=>"Tennessee",'TX'=>"Texas", 'UT'=>"Utah",'VT'=>"Vermont",'VA'=>"Virginia",'WA'=>"Washington",'WV'=>"West Virginia", 'WI'=>"Wisconsin",'WY'=>"Wyoming"); $submit = "Submit mailing information"; ?> <html> <head> <style type='text/css'> <!-- body { background: #42413C; color: #000; font-family: Tahoma, Geneva, sans-serif; font-size: 90%; } form { margin: 1em 2 2 2; padding: 1; width: 1100px; margin-left: 35%; } .field {padding-bottom: 1em; } label { font-weight: bold; float: left; width: 15%; margin-right: 1em; text-align: right; background-color: #9F6; padding-right: 5px; } select {margin-bottom: 1em;} #submit { margin-left: 15%; } h3 { width: 500px; margin-left: 35%; } --> </style> </head> <body> <h3>Please enter your mailing information below:</h3> <?php /* loop that displays the form */ echo "<form action='$_SERVER[PHP_SELF]' method='POST'>"; foreach($rows as $field => $label) if($field == "state") { echo "<label for='$field'>$label</label> <select id='$field' name='$field'>\n"; foreach ( $states_list as $abbr => $sname ) { echo "<option value='$abbr'>$sname</option>\n"; } echo "</select>\n"; } else { echo "<div class='field'><label for='$field'>$label</label> <input id='$field' name='$field' type='text' value='".@$$field."' size='25%' maxlength='65' /></div>\n"; } echo "<div id='submit'> <input type='hidden' name='submitted' value='yes'> <input type='submit' value='$submit'></div>"; ?> </form> </body> </html>Here is the Logic on the combined php file that displays and has the statements on it for the form: <?php /* Program name: exercise_4_form_verifications.php * Description: Program checks all the form fields for * blank fields and verifies them */ if(isset($_POST['submitted']) and $_POST['submitted'] == "yes") { foreach($_POST as $field => $value) { if(empty($value)) { if($field != "first_name") { $blank_array[] = $field; } } else { $good_data[$field] = strip_tags(trim($value)); } } if(@sizeof($blank_array) > 0) { $message = "<p style='color: black; margin-bottom: 0;font-weight: bold; margin-left: 35%'> You didn't fill in one or more required fields. You must enter: <ul style='color: yellow; margin-top: 0; margin-left: 35%; list-style: none' >"; foreach($blank_array as $value) { $message .= "<li>$value</li>"; } $message .= "</ul>"; echo $message; extract($good_data); include("exercise_4_form.inc"); exit(); } foreach($_POST as $field => $value) { if(!empty($value)) { $name_verify = "/^[A-Za-z' -]{1,50}$/"; $phone_verify = "/^[0-9)(xX -]{7,20}$/"; $city_verify = "/^[A-Za-z' -]{1,50}$/"; $address_verify = "/^[A-Za-z0-9 .,'-]{1,50}$/"; $zip_verify = "/^[0-9]{5}(\-[0-9]{4})?$/"; $e_mail_verify = "/^.+@.+\\..+$/"; if(preg_match("/last/i",$field)) { if(!preg_match($name_verify,$value)) { $error_array[] = "$value is not a valid last name"; } } if(preg_match("/phone/i",$field)) { if(!preg_match($phone_verify,$value)) { $error_array[] = "$value is not a valid phone number"; } } // endif phone format check if(preg_match("/city/i",$field)) { if(!preg_match($city_verify,$value)) { $error_array[] = "$value is not a valid city"; } } if(preg_match("/address/i",$field)) { if(!preg_match($address_verify,$value)) { $error_array[] = "$value is not a valid address"; } } if(preg_match("/zip/i",$field)) { if(!preg_match($zip_verify,$value)) { $error_array[] = "$value is not a valid ZIP code"; } } if(preg_match("/e_mail/i",$field)) { if(!preg_match($e_mail_verify,$value)) { $error_array[] = "$value is not a valid e-mail address"; } } } $clean_data[$field] = strip_tags(trim($value)); } if(@sizeof($error_array) > 0) { $message = "<ul style='color: yellow; margin-top: 0; margin-left: 35%; list-style: none' >"; foreach($error_array as $value) { $message .= "<li>$value</li>"; } $message .= "</ul>"; echo $message; extract($clean_data); include("exercise_4_form.inc"); exit(); } else { echo "<ol>"; foreach($_POST as $field => $value) { echo "<h3><li> $field = $value</li></h3>"; } echo "</ol>"; } } else { include("exercise_4_form.inc"); } ?> Edited by mac_gyver, 15 November 2014 - 12:14 PM. code tags around posted code please Hello PHPfreaks! I build a website for a company way back when I was still learning basic PHP! Now unfortunaly the webhost has decided to change their security settings, specifically chaning the allow_url_include and allow_fopen_include to off! That however breaks the website that I did, since i am using the following code in calling the various menus around the website: Code: [Select] include(''$site_url'menu.php?menuid=1'); Now I am well aware that this is not the best way to include a menu! ohhh yeah btw, the code for the menu.php file is: Code: [Select] <?php include('config.php'); $menuid = mysql_real_escape_string($_GET['menuid']); $menu_categories = mysql_query("SELECT * FROM " .$db_prefix. "menucategories WHERE id='".$menuid."'"); while($menu_cat = mysql_fetch_array($menu_categories)) { if($menu_cat['display_name'] == "") { $menu = mysql_query("SELECT * FROM " .$db_prefix. "menu WHERE cat = ".$menu_cat['id']." ORDER BY placement ASC"); echo "<ul>"; while($menu_rows = mysql_fetch_array($menu)) { echo "<li><a href='" .$menu_rows['URL']. "' class='".$menu_cat['name']."' >" .$menu_rows['name']. "</a></li>"; } echo "</ul>"; } else { echo "<h4>" .$menu_cat['display_name']. "</h4>"; $menu = mysql_query("SELECT * FROM " .$db_prefix. "menu WHERE cat = ".$menu_cat['id']." ORDER BY placement ASC"); echo "<ul>"; while($menu_rows = mysql_fetch_array($menu)) { echo "<li><a href='" .$menu_rows['URL']. "' class='".$menu_cat['name']."' >" .$menu_rows['name']. "</a></li>"; } echo "</ul>"; } } ?> So i build the website so that you call the various menus around in the website using the menu.php include and setting a variable based on a ID (i.e menu.php?menuid=2) and of course using variables in the URL name you need to define a complete URL in the include, which now with the hosting companies new security policy doesn't work! SO BASICALLY! What I am trying to ask: Is there any alternative to include menu.php?menuid=XX without using the absolute URL? Hi All, I have a snippet of code (below) which I use to create a dynamic menu from a MySQL database for a community website. Fields used in the database a ID parent (what the parent page is) page_order (what is says on the tin) short_title (a short title for the page for the URL) title (the page title - used as the text for the link) content (the content for the page) I have got the dynamic list to display fine, but what I would like to be able to do is give each list item a 'class' tag when it has been selected (and thus is the page being shown). Can anyone suggest how to amend the below code to allow this? Code is: Code: [Select] <!-- ##### START LIST_INFO_PAGES ##### --> <?php include("../config/config.php"); ?> <?php $sql = "SELECT * FROM `PCNET_$filename` WHERE parent = 'council' ORDER BY page_order ASC"; $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql); while ($row = mysql_fetch_assoc($sql_result)) { print ''; if ($row["status"]<>'') { echo '<li><a href="../council-indiv.php?id='; echo ($row["id"]).'&short_title='; echo nl2br(stripslashes(utf8_decode($row["short_title"]))).'" title='; echo nl2br(stripslashes(utf8_decode($row["title"]))).'>'; echo nl2br(stripslashes(utf8_decode($row["title"]))).'</a></li>'; }; }; ?> <!-- ##### END LIST_INFO_PAGES ##### --> Help will be welcome! Neil I want make the following, (I have already a database with three tables (Countries, Timeline and Category)). 1: list of countries (drop down menu 1), Timeline of the countries history (drop down 2) and Category (drop down 3). 2: The selected values of the drop down menus must show take the information from the database. Can any one help me with the coding? Hi all, my first post here (except my intro post earlier today). I looked for this in the Code Snippet section and didn't see it, and honestly I'm very much a noob at this (for now, at least) so I'm not quite sure what I'd look for anyway. I've got a decent grasp on HTML and CSS and very little PHP. So here's what I need help with: I wrote a simple PHP include so that all my main pages (including the index file) would all use the same file (navtabs.php) for their navigation tabs. But how do I make the code in navtabs.php dynamic for which button should be highlighted on the proper page? Here is the code snippet for my navigation: Code: [Select] <nav> <ul> <li><a href="index.php" class="current">Home</a></li> <li><a href="page-two.php" >Page Two</a></li> <li><a href="page-three.php">Page Three</a></li> <li><a href="page-four.php">Page Four</a></li> <li class="last"><a href="page-five.php">Page Five</a></li> </ul> </nav> Where class="current" is the highlighting attribute. All my pages using the same include of this code show the Home tab highlighted? Hoping someone has a simple fix for me. Thanks! Hi guys! I need a php page that is splitted into 2 screens. One will display the navigation menu and the second one is the iframe. As for the navigation menu, I am getting the list of all files in the current directory with readdir(). Then I create an array with all of the items that are folders (is_dir() function) and apply the same script on them. My problem is to correctly display all of the information I gather in an adequate manner. Can anyone help me with that? Also if anyone has ready-to-go scripts, I would highly appreciate that too. Also, once a user choose a file, it should be loaded in the iframe. How do I specify "src" attribute for the iframe, in that case? Thanks! Hey Guys, I'm building a site and I need a drop down menu created dynamicly.... This is the flat html code Code: [Select] <div class="art-nav"> <div class="l"></div> <div class="r"></div> <ul class="art-menu"> <li><a href="URL 1"><span class="l"></span><span class="r"></span><span class="t">TOP LEVEL</span></a> <ul> <li><a href="URL 1">SUB CAT 1</a></li> <li><a href="URL 2">SUB CAT 2</a></li> <li><a href="URL 3">SUB CAT 3</a></li> </ul> </li> <li class="art-menu-li-separator"><span class="art-menu-separator"></span></li> <li><a href="URL 5"><span class="l"></span><span class="r"></span><span class="t">Contact Us</span></a></li> </ul> </div> This is the code that shows a dyamic code, but not in the menu... <?php wpsc_start_category_query(array('category_group'=> get_option('wpsc_default_category'), 'show_thumbnails'=> get_option('show_category_thumbnails'))); ?> <a href="<?php wpsc_print_category_url();?>" class="wpsc_category_link"><?php wpsc_print_category_name();?></a> | <?php wpsc_print_subcategory(); ?> <?php wpsc_end_category_query(); ?> I'm trying to figure it out why my code it's only updating the last menu or submenu of a menu. The menu and submenu are stored in the same database and the parent_id is equal to the id for the sub-menus . Parent_id = 0 means it's a main menu. Help! hii,everyone... i am new to the forum ..so forgive me if i make some errors in describing my problem i want to create a drop down menu...the values of which i want to retrieve from a table i have created in my database... i have been able to acheive this...but i want a second drop down menu...in which i want the values to get filtered according to the selection of the first drop down menu... i hav a table with the name test...which i am connecting to the first drop down menu i hav created another table with the name testtype...for second menu.. the id of first table is the testid of second... plzz help me with creating the second menu... my code is Code: [Select] <?php $sql_result = "select test_series FROM test"; $result = mysql_query($sql_result); ?> <td>Select Test Series </td> <td> <select name="testseries" id="testseries" )"> <option>Select</option> <?php if(mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)) { $test = $row['test_series'];?> <option><?php echo $test ?></option> <?php } } else {?> <option>No Names Present</option>"; <?php } ?> </select> </td> </tr> <tr> <?php $testseries = $_POST['testseries']; $query = "select id from test where test_series = '$testseries'"; $resultt = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($resultt); $id = $row['id']; $sql_result = "select test_name FROM testtype where testid = $id"; $result = mysql_query($sql_result); ?> <td>Select Test Name </td> <td> <select name="testtype"> <option>Select</option> <?php if(mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)) { $test2 = $row['test_name'];?> <option><?php echo $test2 ?></option> <?php } } else {?> <option>No Names Present</option>"; <?php } ?> </select> </td> </tr> IN THIS CODE I AM GETTIN AN ERROR Undefined index: testseries in ..addques.php on line 155 WHICH IS THIS ONE $testseries = $_POST['testseries']; Hi all. I'm working on a project that requires a 3 tier navigation menu that's dynamic and I'm not quite sure where to start with it. The structure of the menu is like so... A unique list of Parent-Modules Tier1: Parent-Module1 Each parent module has a second tier menu that appears upon clicking a parent module. Each parent module has a unique list of tier 2 sub modules Tier 2: Sub-Module1 - Sub-Module2 Each sub module has a third tier menu that appears upon clicking a sub module. Each sub module has a unique list of tier 3 child modules Tier 3: Child-Module1 - Child-Module2 - Child-Module3 A visual: Parent (each parent module has this structure) | |--------Sub Module | |-Child Module 1 | |-Child Module 2 | |-Child module 3 |--------Sub Module | |-Child Module 1 | |-Child Module 2 | |-Child module 3 |--------Sub Module |-Child Module 1 |-Child Module 2 |-Child module 3 Every tier has to be dynamic as the module names/locations are often changed. My thought is to use opendir/readdir in order to build the tiers based on what files exist, but I'm not sure if this is a safe/reliable practice. Any input would be a great help. EDIT: The navigation links would have to have "pretty" names (e.g. Business Processes instead of business_processes). i have created a seating system. based on the number of seats booked that value is passed to a page that dynamicly produces a drop down box for each seat booked so the type of seat price can be assigned. this part works fine. the problem i have is how do i code the recieving page not knowing how many values are going to be passed? this is the drop down menu page Thanks Code: [Select] <form action="payment.php?seatco=<?php echo $s_count; ?>" method="post" name="f1"> <div id="tick_select"> <?php for($i=1; $i<=$s_count; $i++){ $tick= mysql_query("select * from ticket_list"); ?> <select name="tick_com<?php echo $i; ?>" id="tick_com" onChange="" title="Choose A Ticket"> <option value="">Select Ticket type</option> <?php while($result= mysql_fetch_assoc($tick)) { ?> <?php echo '<option value="'.$result[ticket_id].'" name="'.$result[price].'">'.$result[type].'</option>';?> <?php }}?> </select> </div> <INPUT TYPE="submit" VALUE="Select"> </form> I'm trying to create a dynamic option menu with one alert selected based on the first query to the db. Any help would be greatly appreciated. Code: [Select] //function to get alerts and create select menu with current alerts pre-selected function getALERTS1($id){ require('db.php'); $alert = mysqli_query($conn, "SELECT alert1 FROM visit_data WEHERE patientid = $id AND discharged IS NULL"); $row = mysqli_fetch_array($alert); $selects=null; $query = mysqli_query($conn, "SELECT alertid, name FROM alerts"); while($row1 = mysqli_fetch_array($query)) { $selects .= "<option value=\"" . $row1['alertid'] . "\"> if($row1['alertid']==$row['alert1']) { echo ' selected'; } ".$row1['name']."</option>"; } return $selects; } Hi guys, I'm still not having any luck with coming up with an idea of how to make my multi-level drop down menu work with items from a database. I don't necessarily need code, but an idea of how to make it work, so any ideas are welcome. The table: Column Descriptions: id - The unique id label - The text to display link - The link to be used relation - I cannot remember why I wanted that... just disregard it parent - The parent item's id (0 for no parent) sort - A sort number for the item (ascending) active - 0 for false, 1 for true (not implemented yet, will add a WHERE `active` = 1 into the sql later) depth - How many parent items there are Now, here's what it has to do (the class): Grab items from the database (sorted by depth, parent, and sort) Place the children in a child array of the parents (or however it can be sorted) Implode the array and turn it into an html menu with the below structure Menu HTML Structure Code: [Select] <div id="menu"> <ul> <li><h2>Level 1 A</h2> <ul> <li><a href="?r=level2/a">Level 2 A</a> <ul> <li><a href="?r=level3/a">Level 3 A</a></li> <li><a href="?r=level3/b">Level 3 B</a></li> </ul> </li> </ul> </li> <li><a href="?r=level1/b"><h2>Level 1 B</h2></a></li> </ul> </div> And here is the code I have so far, but I can't figure out how to get the children into the parent array, or at least sort it so that I can achieve the above HTML structure. Thank you in advance for your help, and as I said above, I don't necessarily need code, but an idea of how to make it work, so any ideas are welcome. I am having a lot of trouble with this code, and I have no clue how to fix it. Right now, I have a GUI for a fictitious car dealership that has 5 populated drop down menus called Make, Model, Year, Color, and Mileage. What I want the code to do is read the selections made by the user with the drop down menus once the user hits the submit button and then filter the tables that I have in a mysql database to meets the choice requirements of the user. The code will bring up the GUI, but once I hit the submit button, I get the following errors Please if anyone can help me that would be fantastic. I really have no clue This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=352987.0 Hi there. Im a noob to sql and php not sure if this is right place to post, Im trying to get a dynamic drop down menu to show the 1st column in my sql database the column is called cat and holds category info ie audio, internet, music ect. ( i have no idea how to do lol ) it has taken me 2 days to find and edit this the bold and underline'd bit is what im trying to change with the dropdown menu. Or thinking bout it is there a way to do it with the URL. IE.. page name.php?cat=audio ? would that be easer ? is there any security issues with doing it that way ? Code================================== $db_host = '*******'; $db_user = '******'; $db_pwd = '*****; $database = 'nbbcj_co_uk'; $table = 'penapps'; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // sending query $result = mysql_query("SELECT * FROM {$table} WHERE `cat` = 'audio' LIMIT 10 "); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); //echo "<h1>Table: {$table}</h1>"; echo "<table border='1' width='100%'><tr>"; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); //echo "<td>{$field->name}</td>"; } echo "</tr>\n"; // printing table rows while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } mysql_free_result($result); ?> code end ====================== the test page can been seen here http://www.nbbcj.co.uk/testd/1/test1.php Any more questions let me know Thanks for any help you can give, a we all have to start some ware lol thanks kaine. |