PHP - Navigation Menu With Php Arrays
Hi PHP Freaks!
Here is my problem. I want to have a PHP navigation system that uses Arrays to control it. Code: [Select] $nav = array( "title1" => "url1", "title2" => array( "sub-page1" => "url1", "sub-page2" => "url2" ), "title3" => array( "sub-page1" => "url1", "sub-page2" => "url2" ), "title4" => array( "sub-page1" => "url1", "sub-page2" => "url2" ), "title5" => "url1", "title6" => "url1" ); $loc = basename($_SERVER["REQUEST_URI"]); What I'm trying to do, is if the $loc is a url in "title4" I want a ul/li printout of that array. Any help you could share with me would be MUCH appreciated. The printout should look like: Code: [Select] <ul> <li>Title4<ul> <li>url1</li> <li>url2</li> </ul></li> </ul> Similar TutorialsHello, I hope someone can help me with this as I really cant seem to get it to work! I am wanting to create a navigation menu from data on a SQL database table, I know how I need to present the data to create the menu but I can not get it to work. Here is an example of what I need: //get the top menu $sql = "SELECT name, link FROM menu WHERE category = 'none'"; $result = mysql_query($sql,$conn); while($row=mysql_fetch_assoc($result)) { $topmenu[] = $row['name']; } //go through the top menu names foreach($topmenu as $top) { //echo the current top meny name echo $top."<br />\n"; //get menu name and link if it matched the current top menu name $sql = "SELECT name, link FROM menu WHERE category = ".$top.""; $result2 = mysql_query($sql,$conn); while($row2=mysql_fetch_assoc($result2)) { //show the menu name and link echo $row2['name']."<br />\n"; echo $row2['link']."<br />\n"; } //create space between top menu names echo "<br /><br />"; } This was my first attempt which did not work at all but since then I have tried multiple things such as putting all the data into multiple arrays, in to one array etc but I couldnt get anything to produce the result that I need. what I am hoping to produce is something like: Home Information Info1 Info2 Info3 About us About us1 About us1 etc etc Once I can produce the data in this way I can then add the html, css etc to create the menu. I will be very greateful for any help and advice that you can provide. Kind Regards Ben 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! 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). Code: [Select] <div id="nav"> <ul> <li class="item"><a href="/">Home</a>/</li> <li class="item"><a href="/one">one</a></li> <li class="item"><a href="/two>two</a></li> <li class="item"><a href="/three">three</a></li> </ul> <div> i want to add class='active' to the a tags . when the menu is the current page. namely.when i on the home page. the a label is Code: [Select] <li class="item"><a href="/" class="active">Home</a>/</li> .but the others a label are not have class="active". when i on the one page. it is is Code: [Select] <li class="item"><a href="one" class="active">one</a>/</li>.the others a label are not have class="active". Using unordered list, <ul> Reading from XML file, Taking menu name from database, Is there other system to make dropdown navigation menu? Which is the best way to make dropdown navigation menu? I also want to show the sitemap of navigation.How can it be done? In CSS, most people add most styling to the A tag instead of UL or LI. Do you know why?
Hi, I am am looking to develop further the code below. This code allows me to display a left navigation bar with Main Links and then if you click a Main link, that link is listed first in the list and its' submenu appears below. For the majority of links in the navigation bar this is fine. But for about 2 of the Main links this basic navigation is not suitable. I need the navigation for 2 of the links to offer more depth. So, for example, if you click Accessories in: Shoes Trousers Shirts Accessories Looks like this if Accessories is clicked: Accessories Belts Cuff Links Wallets Shoes Trousers Shirts Looks like this if belts is clicked (Main link name changed and submenu changed): Accessories - Belts Brown leather Black Leather Multicolour Designs All casual All formal Shoes Trousers Shirts Looks like this is Brown Leather is clicked: Brown Leather Belts Armani Brown Leather Belt 32" Armani Brown Leather Belt 34" Hugo Boss Brown Leather Belt 32" Hugo Boss Brown Leather Belt 34" Shoes Trousers Shirts Currently the code does not allow for this depth in the navigation bar. Any ideas how it could be done? Do I need additional tables for each subcategory. How do I ensure the category clicked does not appear in the rest of the navigation bar, as in the code I have at the moment? Currently the code is: $res = mysql_query("SELECT * FROM categories"); while($row = mysql_fetch_array($res)) { $cats[$row['categoryid']] = $row['categoryname']; } if(isset($_GET['category'])) { $selcat = $_GET['category']; } if(isset($_GET['product'])) { $prod_info = mysql_fetch_array(mysql_query("SELECT * FROM products WHERE productid = ".$_GET['product'])); //Prod_Info now gets stored for use in the main display. $selcat = $prod_info['categoryid']; } if(isset($selcat)) { echo "<a href='categorylist.php?category=".$selcat."'>".$cats[$selcat]."</a>"; unset($cats[$selcat]); //Gets rid of it for later. $res = mysql_query("SELECT productid,name FROM products WHERE categoryid = ".$selcat); while($row = mysql_fetch_array($res)) { echo "<a href='product.php?product=".$row['productid']."'>".$row['name']."</a>"; } } foreach($cats AS $key => $cat) { echo "<a href='categoryview.php?category=".$key."'>".$cat."</a>"; } Thank you for looking at this post, Matt. I have this thing that i am trying to make but i cant get it to work.. can anyone help? Code: [Select] function sql_read( $dbname,$dbusername,$dbpassword ) { $names = array(); $password = array(); $connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect"); @mysql_select_db ($dbname) or die("Could not find DataBase"); $query = mysql_query("select * from users"); $numrows = mysql_num_rows($query); if ($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $names[] = $row["uname"]; $password[] = $row["password"]; $id = $row["id"]; } $return = array($names,$password,$id); }else{ $return = array(); } return $return[]; } $names = array(); $names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0]; The error i get is Code: [Select] Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28 Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];" Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks! I'm having troubling with trying to create a function to spit out a single array with the following array. I can write it in a away that looks through the arrays manually. the results i am trying to generate is that each item in generated array. Array to convert array( "account" => array( "login", "register", "logout", "edit", ), "p" => array( "report", ), "array1.0" => array( "array2.0" => array( "array3.0", "array3.1 ), "array2.1", ), generating the array will look like this
Array ( [0] => account [1] => account/login [2] => account/register [3] => account/logout [4] => account/edit [5] => p [6] => p/report [7] => array1.0 [8] => array1.0/array2.0 [9] => array1.0/array2.0/array3.0 [10] => array1.0/array2.0/array3.1 [11] => array1.0/array2.1 ) The idea is that id generates a single array with combined labels and arrays inside, etc. I just can't figure out how to create a script that will create this array even If I add a new value or array.
I have two arrays, both with the same key values. I'd like to combine them. So for instance... Code: [Select] <?php $array1['abcd'] = array( 'value1' => "blah", 'value2' => "blahblah"); $array1['efgh'] = array( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz"); $array2['abcd'] = array('value3' => "three", 'value4' => "four"); $array2['efgh'] = array( 'value3' => "hohoho", 'value6' => "six6"); function combine_arrays($array1,$array2) { //*combining* return $single_array; } echo "<pre>"; print_r(combine_arrays($array1,$array2)); echo "</pre>"; /* would produce ['abcd'] = ( 'value1' => "blah", 'value2' => "blahblah", 'value3' => "three", 'value4' => "four" ) ['efgh'] = ( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz", 'value3' => "hohoho", 'value6' => "six6" ) */ ?> What's the easiest way to do this? Let's say I have an array like this: Man1(0), Man1(1), Man1(2), etc. Man2(0), Man2(1), Man2(2), etc. Man3(0), Man3(1), Man3(2), etc. ... and I want to loop through the array. I know I can do: Code: [Select] $i=0; while $i<=99 {//...do something with Man1[$i];} i++; but can I also do a loop with each Man? Like: Code: [Select] $i=0;$a=1; while $i<=99 {//...do something with Man$a[$i];} i++;a++; I've written all the code for each Man separately and I'm thinking there's got to be a way to shorten the code with another loop, but I don't know how. Hope that makes sense. Thanks. Hi i'am try to insert multiple data on a single submit, but i'm a total noob to Arrays, can any one help me out here... one of the members send me this out, but still i can figure it out how to insert the fields onto my database. it inserts but doesnt get the valuee.. Please help! if(isset($_POST['save'])) { unset($_POST['save']); $i = count($_POST['id']); $x = 0; for($x=0; $x <$i;$x++){ foreach($_POST as $data =>$d){ echo $data.'-'.$d[$x].'<br/>'; $insert = mysql_query("insert into tbl_grades"); //sql statement here (example): insert into table name (value of $data) values( value of$d[$x]) -- can anyone help me with this , how can i query to get the value of this, //HOW DO I MAKE MY SQL QUERY TO SAVE THIS OUT, I KNOW THIS IS MY PROBLEM IN THE QUERY.... here's my HTML <input name="id[]" type="hidden" value="<?php echo $row['id'];?>" /> 1st<input name="fg[]" type="text" id="fg[]" size="1" value="<?php $g_sub['sub_id'];?>"/> 2nd<input name="sg[]" type="text" id="sg[]" size="1" value="<?php $g_sub['sub_id'];?>"/> 3rd<input name="tg[]" type="text" id="tg[]" size="1" value="<?php $g_sub['sub_id'];?>"/> 4th <input name="forg[]" type="text" id="forg[]" size="1" value="<?php $g_sub['sub_id'];?>"/> ---- sub_id stands for subject id Hello, I have 2 array questions that I'm hoping someone can help me with. 1) First, I'm trying to add elements to a previously existing array. I start with: $data = array('text' => $_POST['text'], 'question_type' => $_POST['question_type'], 'solution' => $_POST['solution'], 'filename' => $filename, 'author_id' => $_POST['author']); Then, under certain circumstances, I'm going to want to add the following to the array $data: 'incorrect_solution1' => $_POST['incorrect_solution1'], 'incorrect_solution2' => $_POST['incorrect_solution2'], 'incorrect_solution3' => $_POST['incorrect_solution3']) I tried the concatenation function, combined with an if statement but then PHP thinks that I have a string. 2) Once I have the array, I want to shuffle the solution and 3 incorrect solution indices. I'm not sure how to shuffle just a portion of an array. Any help with either or both questions would be appreciated. Thank you. I have some similar arrays. How I can combine them to shuffle the new array? I can't work out the quotes around this... $bookingID['$row['id']'] = $row['id']; echo $bookingID['$row['id'];']; Parse error: parse error, expecting `']'' What would fix this? I'm not sure if this can be done, but I would like to get the sum for each $.row[''] result ex: if $row['robotics'] had values of 100,150,300 I would like to be able to show a total of 550 Code: [Select] <?php echo "<Table border=1>"; echo "<tr><td></td><td>Robotics</td><td>Chiral Stuctors</td><td>Enriched Uranium</td><td>Mechanical Parts</td><td>Coolant</td><td>Consumer Electronics</td><td>Precious Metals</td><td>Reactive Metals</td><td>Oxygen</td><td>Toxic Metals</td></tr>"; $result = mysql_query("select * from `pi`"); while ($row = mysql_fetch_array($result)) { echo "<tr><td>".$row['pilot']."</td>"; echo "<td>".$row['robotics']."</td>"; echo "<td>".$row['chiralstuctors']."</td>"; echo "<td>".$row['enricheduranium']."</td>"; echo "<td>".$row['mechanicalparts']."</td>"; echo "<td>".$row['collant']."</td>"; echo "<td>".$row['consumerelectronics']."</td>"; echo "<td>".$row['preciousmetals']."</td>"; echo "<td>".$row['reactivemetals']."</td>"; echo "<td>".$row['oxygen']."</td>"; echo "<td>".$row['toxicmetals']."</td></tr>"; } echo "</table>"; ?> Hello, I have an array, $solutions, and a separate indexing array, $solution_order. From the $solution_order array (developed from the $order variable, where each $order variable looks like '0321' or '3021'), I'd like to create a new array $ordered_solutions, which indexes on the values picked from the $solution_order array. For example, if my $solutions array is (Big, Small, Fat, Skinny) and my $solution_order array is (2,3,1,0), then the final results should be (Fat, Skinny, Small, Big). I've written down what I have so far. Any thoughts about how to move this forward would be appreciated. Thanks! function GetOrder($solution, $wrong1, $wrong2, $wrong3, $order) { $solutions = array( $solution, $wrong1, $wrong2, $wrong3); $solution_order = array(substr($order,0,1), substr($order,1,1), substr($order,2,1), substr($order,3,1)); $ordered_solutions = array(); //what do to here?? return $ordered_solutions; } Hi Guys, I have an array Code: [Select] $arr When i run this function Code: [Select] print_r($arr) I get the output below:- -------------------------------- Code: [Select] Array ( [WHMCSAPI] => Array ( [ACTION] => getclientsproducts [RESULT] => success [CLIENTID] => 87 [PID] => 13 [DOMAIN] => dfgbhcgnd.com [TOTALRESULTS] => 1 [STARTNUMBER] => 0 [NUMRETURNED] => 1 [PRODUCTS] => Array ( [PRODUCT] => Array ( [ID] => 196 [CLIENTID] => 87 [ORDERID] => 218 [PID] => 13 [REGDATE] => 2011-12-07 [NAME] => Walderizer [DOMAIN] => dfgbhcgnd.com [DEDICATEDIP] => [SERVERID] => 3 [FIRSTPAYMENTAMOUNT] => 55.00 [RECURRINGAMOUNT] => 55.00 [PAYMENTMETHOD] => banktransfer [PAYMENTMETHODNAME] => Bank Transfer [BILLINGCYCLE] => Monthly [NEXTDUEDATE] => 2011-12-07 [STATUS] => Active [USERNAME] => vitaforiz [PASSWORD] => ghTfg476fg [SUBSCRIPTIONID] => [LASTUPDATE] => 0000-00-00 00:00:00 [CUSTOMFIELDS] => Array ( [CUSTOMFIELD] => Array ( [NAME] => IP Address [VALUE] => ) ) [CONFIGOPTIONS] => ) ) ) ) --------------------------------- My question is, how can i print only certain parts of the data rather than printing the whole array. For example i only want to echo the values for [NAME], [USERNAME], [PASSWORD] and [NEXTDUEDATE] from the [PRODUCT] part of the array Thanks in advance Hello! i want to store data in a array (as seen in the code). Im trying to make it so that a php code search through the arrays and find the correct one. once it does it tells me. I dont know if im close, How ever this is what i have. $carrier = $_POST['carrier']; $carriers = array( array("verizon","tmobile","sprint","att","virgin","textnow","metro","unknown"), array("@vtext.com","@tomomail.net","@messaging.sprintpcs.com","@txt.att.net","@vmobl.com","@textnow.me","@mymetropcs.com","@teleflip.com") ); If ($carrier = I am trying to learn about sorting and modifying arrays and I am practicing on a book assignment but need some help to grasp what I need to do. If you go here, you will see how it is supposed to work. http://198.86.244.3/mabarckhoff/WEB182/ch11_ex1/ I need to write a case to sort the task when you click the sort button and modify when you click that button. The delete button works and the add task works. I understand the sort array and have added that case, but don't know how to get it to work with the submit. Also there is a promote button so would need 'promote' what ever you have chosen in the dropdown menu to the top. Here is my code. tasklist.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> <title>Task List Manager</title> <link rel="stylesheet" type="text/css" href="main.css"/> </head> <body> <div id="page"> <div id="header"> <h1>Task List Manager</h1> </div> <div id="main"> <!-- part 1: the errors --> <?php if (count($errors) > 0) : ?> <h2>Errors:</h2> <ul> <?php foreach($errors as $error) : ?> <li><?php echo $error; ?></li> <?php endforeach; ?> </ul> <?php endif; ?> <!-- part 2: the tasks --> <h2>Tasks:</h2> <?php if (count($task_list) == 0) : ?> <p>There are no tasks in the task list.</p> <?php else: ?> <ul> <?php foreach( $task_list as $id => $task ) : ?> <li><?php echo $id + 1 . '. ' . $task; ?></li> <?php endforeach; ?> </ul> <?php endif; ?> <br /> <!-- part 3: the add form --> <h2>Add Task:</h2> <form action="." method="post" > <?php foreach( $task_list as $task ) : ?> <input type="hidden" name="tasklist[]" value="<?php echo $task; ?>"/> <?php endforeach; ?> <label>Task:</label> <input type="text" name="newtask" id="newtask"/> <br /> <label> </label> <input type="submit" name="action" value="Add Task"/> </form> <br /> <!-- part 4: the modify/promote/delete form --> <?php if (count($task_list) > 0 && empty($task_to_modify)) : ?> <h2>Select Task:</h2> <form action="." method="post" > <?php foreach( $task_list as $task ) : ?> <input type="hidden" name="tasklist[]" value="<?php echo $task; ?>"/> <?php endforeach; ?> <label>Task:</label> <select name="taskid"> <?php foreach( $task_list as $id => $task ) : ?> <option value="<?php echo $id; ?>"> <?php echo $task; ?> </option> <?php endforeach; ?> </select> <br /> <label> </label> <input type="submit" name="action" value="Modify Task"/> <input type="submit" name="action" value="Promote Task"/> <input type="submit" name="action" value="Delete Task"/> <br /> <label> </label> <input type="submit" name="action" value="Sort Tasks"/> </form> <?php endif; ?> <!-- part 5: the modify save/cancel form --> <?php if (!empty($task_to_modify)) : ?> <h2>Task to Modify:</h2> <form action="." method="post" > <?php foreach( $task_list as $task ) : ?> <input type="hidden" name="tasklist[]" value="<?php echo $task; ?>"/> <?php endforeach; ?> <label>Task:</label> <input type="hidden" name="modifiedtaskid" value="<?php echo $task_index; ?>" /> <input type="text" name="modifiedtask" value="<?php echo $task_to_modify; ?>" /><br /> <label> </label> <input type="submit" name="action" value="Save Changes"/> <input type="submit" name="action" value="Cancel Changes"/> </form> <?php print_r($_POST); ?> <?php endif; ?> </div><!-- end main --> </div><!-- end page --> </body> </html> index.php <?php if (isset($_POST['tasklist'])) { $task_list = $_POST['tasklist']; } else { $task_list = array(); // some hard-coded starting values to make testing easier $task_list[] = 'Write chapter'; $task_list[] = 'Edit chapter'; $task_list[] = 'Proofread chapter'; } $errors = array(); switch( $_POST['action'] ) { case 'Add Task': $new_task = $_POST['newtask']; if (empty($new_task)) { $errors[] = 'The new task cannot be empty.'; } else { $task_list[] = $new_task; } break; case 'Delete Task': $task_index = $_POST['taskid']; unset($task_list[$task_index]); $task_list = array_values($task_list); break; case 'Sort Task': sort($task_list); print_r($task_list); break; /* case 'Save Changes': case 'Cancel Changes': case 'Promote Task': */ } include('task_list.php'); ?> |