Hello All, I am using wordpress for CMS based application,My menu is dynamic like services, in services i want my client to add new services as when they want without any technical knowledge now those services should appear in services drop down automatically so when we add new services the drop down should have listed in it. What changes i have to make for this in my html pages given by designer. Thanks Harshida
This is a question impossible to answer. Please be more specific. How could I for example know what the designer did for you? Let me know more.
A while back I made a triple menu system that pulled values from databases. Let me know if this is something similar to what you want and I will post the code up. http://homeworkslackers.com/members/triplemenustandalone.php You might only want 1 menu, in which case it would be even simpler code . I've also got the code to add new "courses / classes / curricula", or in your case, services.
Interesting functionality. I would like to know more about this if possible. Maybe a link to some documentation etc? I have a project that I would like to updated, a booking system that has a dropdown for years, month and days, and I think this could help me. Thanks in advance!
The complex part of the script has to do with live updating and re-writing the entire menu each time the menu is loaded. If you have a set array of values it may not be as helpful but because members can add classes / courses / curricula when they sign up and I wanted to include them all instantly, it simply creates a new menu every time it loads... but here goes nothing! this is the stand alone version - you can put this all in a PHP file, run it, and watch it go. There were a lot of weird, random tid-bits that didn't make sense at the time as well as relatively poor comments / documentations towards the end (when I got lazy ). Its a pretty nasty PHP/Javascript combo but it gets the job done. I also attached the SQL for the table "search1". <html> <head> <title>Test Page</title> <?php echo '<script type="text/javascript">'."\n"; $link = mysql_connect("host", "username", "password") or die(mysql_error()); mysql_select_db("db_name") or die(mysql_error()); $result1 = mysql_query("SELECT * FROM search1 ORDER BY classes ASC"); $lim1 = mysql_num_rows($result1); $c = 0; while ($row1 = mysql_fetch_array($result1)){ $v = 0; $w = 0; $y = 0; $z = 0; $class0 = $class1; $class1 = $row1['classes']; //get all course options into array for this class on the condition that the class is unique $result2 = mysql_query("SELECT * FROM search1 WHERE classes='$class1' ORDER BY courses ASC"); $lim2 = mysql_num_rows($result2); while ($row2 = mysql_fetch_array($result2)){ $courseARR[$y] = $row2['courses']; $course0 = $course1; $course1 = $courseARR[$y]; if ($course0 != $course1){ $y++; } } $z = $y; $y = 0; //$courseARR now contains every course present for the class //we somehow have to update the $courseARR[$y] for every time the last curriculum is discovered. We do this by making a counter variable start at zero and work its way up towards the limit of the curriculums for that class. The limit must be updated each time too, however, so this is put in at the end of the while loop as well. while ($y < $z){ $w = 0; $result3 = mysql_query("SELECT * FROM search1 WHERE classes='$class1' AND courses='$courseARR[$y]' ORDER BY curriculum ASC"); $lim3 = mysql_num_rows($result3); while ($row3 = mysql_fetch_array($result3)){ $curriculumARR[$w] = $row3['curriculum']; $w++; } $w = 0; //we now have everything we need to create an option. The Curriculum array holds every curriculum for that course while (($w < $lim3) && ($class1 != $class0)){ //$option = $class1.'.'.$courseARR[$y].'.'.$curriculumARR[$w]; $option[$c][0] = $class1; $option[$c][1] = $courseARR[$y]; $option[$c][2] = $curriculumARR[$w]; //echo 'IMPORTANT: '.$lim3.'*'.$c."\n"; $c++; $w++; } $y++; } } /*with the current setup, the list should go in this order (math only)... math.algebra.cpm math.algebra2.cpm math.calculus.other math.geometry.cpm math.pre-algebra.cpm math.pre-algebra.other math.precalculus.precalculus: a graphing approach */ //at this point we have any number of $option.$c's, somewhere around 100 maximum, in the form of Math.Pre-Algebra.CPM. //old: echo 'options[$x]=new Option("'.$curriculum.'","http://homeworkslackers.com/members/'.$class.'/'.$course.'/'.$curriculum.'/index.php");'; //**********************************BEGIN TRIPLE MENU CODING************************************ // echo '//new Option("text","value")'."\n"; echo '//this code changes menus'."\n"; echo 'function nullOptions(aMenu){'."\n"; echo 'var tot=aMenu.options.length'."\n"; echo 'for (i=0;i<tot;i++)'."\n"; echo '{'."\n"; echo 'aMenu.options[i]=null'."\n"; echo '}'."\n"; echo 'aMenu.options.length=0;'."\n"; echo '}'."\n"; $i = 1; $letter = 'a'; $lim4 = $c; $c = 0; $b = -1; $numberofcurriculums = 0; //while ($lim4 >= $c){ // explode('.', $option.$c); // $c++; // } //$c = 0; //while ($lim4 >= $c){ // echo $option[$c][0].'***'.$option[$c][1].'***'.$option[$c][2]; // echo "\n"; // $c++; // } //$c = 0; //******************************************************************************************************* //the while loop ends when the last option is reached. Until then, it will do what is inside. The first do while loop outputs the MySubject() stuff as well as all of the options for the curriculum (in the second do while loop). It continues to output the curriculum options until we reach a new course, where it will finish the loop, output the note at the bottom (netscape stuff), and then add one to $i, the counter. It will go back and do the same as long as the next class is the same as the current one. If it is different, it will end the loop, move down another letter in the alphabet, and do the next class's curriculums. All that the chaos below does is dump every possible curriculum into the format needed. while ($lim4 > $c){ do { echo '//*************************Begin*****************************\\'."\n"; // start of files for main option 1 "computer stuff" echo 'function MySubject'.$i.$letter.'(aMenu){'."\n"; echo 'nullOptions(aMenu)'."\n"; echo 'with (aMenu){'."\n"; $x = 1; echo '//Rewrites the text and values'."\n"; echo 'options[0]=new Option("Select a Curriculum","none");'."\n"; do { echo 'options['.$x.']=new Option("'.$option[$c][2].'","/'.$option[$c][0].'/'.$option[$c][1].'/'.$option[$c][2].'/index.php");'."\n"; $x++; $c++; $b++; $numberofcurriculums++; }while (($option[$c][1] == $option[$b][1]) && ($option[$c][1] != NULL)); echo 'options[0].selected=true'."\n"; echo '}'."\n"; echo '//Netscape likes a refresh, but Microsoft doesnt'."\n"; echo '//if (navigator.appName.indexOf("Netscape")>-1)'."\n"; echo '//history.go(0)'."\n"; echo '}'."\n"; $i++; //while the classes are still the same, repeat. }while (($option[$c][0] == $option[$b][0]) && ($option[$c][0] != NULL)); //if the classes are not the same, add one to the letter $letterORD = ord($letter); $letterORD++; $letter = chr($letterORD); $i = 1; } //END WHILE LOOP STUFF //************************************************************************************************************ //at this point we have outputted every curriculum for every course for each class. Next we need to do the same but only for the courses. echo '// ####################### mycourses "mytopics" ####################### //'."\n"; //we have to reset the primary counters because we are moving to the next section. $c = 0; $i = 1; $x = 1; $b = -1; $numberofcourses = 0; //another chaotic while loop... the last of them hopefully. while the counter is less than the limit (max number of options), it will display the header information for the "topic". Sets $x to 1, and then types out the default selection. next, the if loop ensures that repeated courses aren't displayed (which has a high chance of happening). This is not necessary for the curriculum because it is the most specific choice and has no repeats. If it is a repeat (is equal to), then it will not echo the data, but it will add one to all the counters (except $x). If it is still the same subject, the loop will repeat. If it is not the same subject, the loop will end, the default action will be set, and the footer stuff will be put in. In this case, we add one to $i, and begin again if $c is still less than the limit. while ($c < $lim4){ echo 'function MyTopics'.$i.'(aMenu){'."\n"; echo 'nullOptions(aMenu);'."\n"; echo 'with (aMenu){'."\n"; $x = 1; echo '//Rewrites the text and values'."\n"; echo 'options[0]=new Option("Select a Course","none");'."\n"; do { if (($option[$c][1] != $option[$b][1]) && ($b >= 0)){ echo 'options['.$x.']=new Option("'.$option[$c][1].'","");'."\n"; $x++; $numberofcourses++; } $c++; $b++; }while (($option[$c][0] == $option[$b][0]) && ($option[$c][0] != NULL)); echo 'options[0].selected=true'."\n"; echo '}'."\n"; echo '//Netscape likes a refresh, but Microsoft doesnt'."\n"; echo '//if (navigator.appName.indexOf("Netscape")>-1)'."\n"; echo '//history.go(0)'."\n"; echo '}'."\n"; $i++; } echo '// ####################### go() ####################### - stuff i shouldnt touch :-P //'."\n"; echo 'function go(aMenu){'."\n"; echo 'if (aMenu.options.value!="none")'."\n"; echo '{'."\n"; echo 'location=aMenu.options[aMenu.selectedIndex].value'."\n"; echo '}'."\n"; echo 'else'."\n"; echo 'aMenu.options[0].selected=true;'."\n"; echo '}'."\n"; echo '// ####################### setUp ####################### - more stuff i shouldnt touch //'."\n"; echo 'function setUp(){'."\n"; echo 'if (navigator.appName.indexOf("Microsoft")>-1)'."\n"; echo '{'."\n"; echo 'document.formDoubleMenu.menuTopics.options[0].selected=true;'."\n"; echo 'document.formDoubleMenu.menuSubjects.options[0].selected=true;'."\n"; echo 'document.formDoubleMenu.menuFiles.options[0].selected=true;'."\n"; echo '}'."\n"; echo '}'."\n"; echo '// ####################### end of setup ####################### //'."\n"; echo '// ####################### change Subjects ####################### //'."\n"; echo 'function changeSubjects(){'."\n"; echo 'aMenu=document.formDoubleMenu.menuSubjects'."\n"; echo 'aMenu2=document.formDoubleMenu.menuFiles'."\n"; echo 'aMenu3=document.formDoubleMenu.menuTopics'."\n"; echo 'with (aMenu3){'."\n"; //initial case - default echo 'switch (selectedIndex) {'."\n"; echo 'case 0:'."\n"; echo 'nullOptions(aMenu)'."\n"; echo 'nullOptions(aMenu2)'."\n"; echo 'aMenu.options[0]='."\n"; echo 'new Option("Curriculums appear here","none")'."\n"; echo 'aMenu.options[0].selected=true;'."\n"; echo 'history.go(0)'."\n"; echo 'break'."\n"; $cc = 1; $result1 = mysql_query("SELECT * FROM search1 ORDER BY classes ASC"); $lim1 = mysql_num_rows($result1); while ($row1 = mysql_fetch_array($result1)){ $class0 = $class1; $class1 = $row1['classes']; if ($class1 == $class0){ }else{ echo 'case '.$cc.':'."\n"; //first class echo 'nullOptions(aMenu)'."\n"; echo 'nullOptions(aMenu2)'."\n"; echo 'aMenu2.options[0]='."\n"; echo 'new Option("Curriculums appear here","none")'."\n"; echo 'aMenu2.options[0].selected=true;'."\n"; echo 'MyTopics'.$cc.'(aMenu)'."\n"; if ($cc == 3){ echo 'break'."\n"; }else{ echo 'break;'."\n"; } $cc++; } } //MUST ADD THIS TO ALLOW LAST OPTION TO CHANGE THE CURRICULUM echo '//#################TEST BELOW####################'; echo 'case '.$cc.':'."\n"; echo 'nullOptions(aMenu)'."\n"; echo 'nullOptions(aMenu2)'."\n"; echo 'aMenu2.options[0]='."\n"; echo 'new Option("Curriculums appear here","none")'."\n"; echo 'aMenu2.options[0].selected=true;'."\n"; echo 'MyTopics'.$cc.'(aMenu)'."\n"; if ($cc == 3){ echo 'break'."\n"; }else{ echo 'break;'."\n"; } echo '}'."\n"; echo '}'."\n"; echo '}'."\n"; echo '//* ####################### end of change Subjects ####################### //'."\n"; echo '//* ####################### changeFiles ####################### //'."\n"; echo 'function changeFiles(){'."\n"; echo 'aMenu=document.formDoubleMenu.menuSubjects'."\n"; echo 'aMenu2=document.formDoubleMenu.menuFiles'."\n"; echo 'aMenu3=document.formDoubleMenu.menuTopics;'."\n"; echo '//* ####################### set of files for option 1 (JavaScript) ####################### //'."\n"; $cc = 0; $m = 1; $c = 0; $b = -1; $e = 1; $letter = 'a'; while ($lim4 > $c){ do { if ($cc == 0){ echo 'if (aMenu3.selectedIndex=='.$e.')'."\n"; $e++; echo '{'."\n"; echo 'with (aMenu){'."\n"; echo 'switch (selectedIndex) {'."\n"; echo 'case 0:'."\n"; echo 'aMenu2.options.length=0;'."\n"; echo 'aMenu2.options[0]='."\n"; echo 'new Option("Curriculums appear here","none")'."\n"; echo 'aMenu2.options[0].selected=true;'."\n"; echo 'history.go(0)'."\n"; echo 'break'."\n"; //Description }else{ echo 'case '.$cc.':'."\n"; echo 'MySubject'.$m.$letter.'(aMenu2)'."\n"; //course1, course2, course3, etc until new subject is reached... then start over. if ($cc == 3){ echo 'break'."\n"; }else{ echo 'break;'."\n"; } $m++; } $cc++; $b++; $c++; }while (($option[$c][0] == $option[$b][0]) && ($option[$c][0] != NULL)); //MUST ADD THIS TO ALLOW LAST OPTION TO CHANGE THE CURRICULUM echo 'case '.$cc.':'."\n"; echo 'MySubject'.$m.$letter.'(aMenu2)'."\n"; //course1, course2, course3, etc until new subject is reached... then start over. if ($cc == 3){ echo 'break'."\n"; }else{ echo 'break;'."\n"; } $m = 1; $cc = 0; //add one to the letter $letterORD = ord($letter); $letterORD++; $letter = chr($letterORD); echo '}'."\n"; echo '}'."\n"; echo '}'."\n"; } echo '}'."\n"; //******************************END TRIPLE MENU CODING*****************************/ echo '</script>'."\n"; ?> <form name="formDoubleMenu"> <table bgcolor="#FFFFFF" border="0" width="783"> <tr align="center"> <td width="171" valign="top" align="center"> <select style="width:182; height:22" name="menuTopics" onchange="changeSubjects()" size="1"> <option value="none" selected> Classes appear here </option> <?php $result1 = mysql_query("SELECT * FROM search1 ORDER BY classes ASC"); $lim1 = mysql_num_rows($result1); while ($row1 = mysql_fetch_array($result1)){ $class1 = $row1['classes']; if ($class1 != $class0){ echo '<option value="none">'.$class1.'</option>'."\n"; $class0 = $class1; } } echo '<option value="none"> Classes appear here </option>'; echo '</select></td>'."\n"; ?> <td width="196" valign="top" align="center"> <select name="menuSubjects" onchange="changeFiles()" size="1" style="width:196; height:22"> <option value="none"> Courses appear here </option> </select> </td> <td width="392" valign="top" align="center"> <select name="menuFiles" style="width:392; height:22" onchange="go(this)" size="1"> <option value="none"> Curriculums appear here </option> </select></td> </tr> </table> </form> </body> </html> PHP: Fun code, eh?