Jump to content

triple menu PHP / MYSQL


tommyboy123x

Recommended Posts

I'm going to have a website that will have a very dynamic menu structure (one that could change every few minutes) and it is essential that everytime the menu is built, the updated database entries are included.

 

Background:  The site is a homework study site that gives study tools, etc.  So lets say that i want to look up the Math (subject or "class"), Pre-Algebra ("course"), CPM ("curriculum"), i would first select Math in the first drop down menu, then Pre-Algebra in the second, and then CPM in the third.  In the second and Third boxes however, there will be other courses and curriculums to choose from.  Those will be updated very regularly and i do not want to do this manually.

 

Storage:  The database right now is set up for one entry per curriculum since that is the most specific catigory.  example

 

Math | Pre-Algebra | CPM

Math | Pre-Algebra | LeMonte's Pre-Algebra

Math | Pre-Algebra | PRE-ALGEBRA: A GRAPHICAL APPROACH

Math | Geometry    | CPM

Math | Geometry    | LeMonte's Geometry

History | US History | American Pageant 11th Edition

History | US History | American Pageant 13th Edition

 

...etc

 

i wrote an EXTREMELY rough draft that has MAJOR ERRORS!!  IT IS NOT COMPLETE AND I HAVE NOT TRIED TO COMPLETE IT YET

 

$result1 = mysql_query("SELECT * FROM search1 ORDER BY classes ASC");
$result2 = mysql_query("SELECT * FROM search1 ORDER BY courses ASC");
$result3 = mysql_query("SELECT * FROM search1 ORDER BY curriculum ASC");

$lim = mysql_num_rows($result1);

$g = 0;
$x = 0;
$y = -1;
$z = 0;

while ($row1 = mysql_fetch_array($result1)){
$class.$x = $row1['classes'];
if ($class.$x != $classes.$y){
	$x++;
	exit();
	}else{
	$course = $row1['courses'];
	$curriculum = $row1['curriculum'];


	while ($row2 = mysql_fetch_array($result2)){
	 	$courses = $row2['courses'];
	 	//courses is the table value, course is the value we have that we are comparing to the different table values
		if ($courses != $course){
			exit();
			}else{


			while ($row3 = mysql_fetch_array($result3)){
				echo 'options[$g]=new Option("Select a Curriculum","none");';
				$g++;
				$curriculums = $row3['curriculums'];
				if ($curriculums != $curriculum)
                                                //some curriculum's are labaled as N/A or Other and these will be omitted
					while (($curriculum != 'N/A') || ($curriculum != 'Other')){
						echo 'options[$a]=new Option("'.$curriculum.'","http://mywebsite.com/members/'.$class.'/'.$course.'/'.$curriculum.'/index.php");';
					$a++;

 

don't worry about the "options[0]=new Option..." part, that is the javascript for the menu.

 

 

 

Question:  How can i get this so that the class will show up, and then for each class, the courses, and for each of the courses the curriculums, but still grab these values from the database each time [without completelly destroying the server each time you load the page].  This site is expected to have somewhere around 500k to 1m hits per day, so optimization is pretty important, but if i can get a rough script i could optimize it myself.

 

-Tom

Link to comment
https://forums.phpfreaks.com/topic/47513-triple-menu-php-mysql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.