Jump to content

Heck of a time with this dropdown menu


suttercain

Recommended Posts

Hi everyone,

 

I have a dropdown menu that works with three options. The first, which is the year selection, is populated by a PHP defined array

 

function show_year($year) {
$year_arr = array("","1994","1995","1996","1997","1998");
$arr_size = count($year_arr);

 

Based on the choice of year it then populates the manufacturer dropdown from the MySQL database. Then based on that second selection it populates the third dropdown, also from the MySQL database. The user hits submit and they get the results.

 

The Working Three Dropdown Code:

<?php
import_request_variables("gpc","");

function show_year($year) {
$year_arr = array("","1994","1995","1996","1997","1998");
$arr_size = count($year_arr);


for ($i = 0; $i < $arr_size; $i++) {
    if ($year_arr[$i] == $year) 
       print "<option selected value=\"" .$year_arr[$i] ."\">".$year_arr[$i] ."</option>\n";
    else 
       print "<option value=\"" .$year_arr[$i] ."\">".$year_arr[$i] ."</option>\n";
  }
}


function show_manufactur($year,$man)
{

//Result SQL statement        
        $sql="SELECT * FROM " .$year. "data GROUP by MFR";

//Connect to server
require_once ("connect.php");

//Count the number of results
        $result = mysql_query("SELECT * FROM " .$year. "data GROUP by MFR");
        
        //$rows = mysql_result($result, 0, 'total');
        $rows = mysql_num_rows($result);

//Populate the drop down list        
        $addblankspace = "";
        print "<option value=\"" .$addblankspace ."\">".$addblankspace ."</option>\n";
        for ($i = 0; $i < $rows; $i++) 
        {
        $tempmfr = mysql_result($sql_result,$i,'MFR');
        
        if ($tempmfr == $man) 
          print "<option selected value=\"" .$tempmfr."\">".$tempmfr."</option>\n";
        else 
          print "<option value=\"" .$tempmfr ."\">".$tempmfr ."</option>\n";

        }  
        $sql = "";
//Close the database connection
         mysql_close();
}


function show_model($year,$man)
{


//Result SQL statement        
        $sql="SELECT * FROM " .$year. "data WHERE MFR = '" .$man. "' GROUP by MODEL";

//Connect to server
require_once ("connect.php");

//Count the number of results
        $result = mysql_query("SELECT * FROM " .$year. "data WHERE MFR = '" .$man. "' GROUP by MODEL");
        
        $rows = mysql_num_rows($result);

//Populate the drop down list        
        $results = array();
for ($i = 0; $i < $rows; $i++) 
{
$results[] = mysql_result($sql_result, $i, 'MODEL');
}

natsort($results);

foreach($results as $result)
{
print "<option value=\"" . $result . "\">" . $result . "</option>\n";
}
//Close the database connection
         mysql_close();
}

?>


<script language=javascript>
function showyear(year) 
{
  refresh = "./verdevdatabase.php?year=" + year; 
  location.href=refresh;
}

function showmodel(man,year) 
{
  refresh = "./verdevdatabase.php?man=" + man + "&year=" + year ; 
  location.href=refresh;
}
</script>


<form action="verdevquery.php" method="POST" enctype="application/x-www-form-urlencoded">
  <center>
  <table width="375" border="0" align="left" cellpadding="0" cellspacing="0">
<TR>
  <TD><div align="left"><strong>Search by Engine Family Name:</strong></div></TD>
  </TR>
<TR>
  <TD><div align="center">
        <p align="left">
          <input name="efn" type="text" id="efn" size="25">
        </p>
    <p align="left">
      <input name="searchtype" type="submit" id="searchtype" value="Search by EFN" />
        </p>
    </div>
    <div align="left"></div></TD>
  </TR>
<TR>
  <TD> </TD>
  </TR>
<TR>
  <TD> </TD>
  </TR>
<TR>
  <TD> </TD>
  </TR>
<TR>
  <TD><div align="left"><strong>Browse by Engine Year, Manufacture and Model:</strong></div></TD>
  </TR>
<TR>
	<TD WIDTH="375"><CENTER>
	  

		<TABLE WIDTH="362" HEIGHT="139" BORDER="0" align="left" CELLPADDING="0" CELLSPACING="0">
			<TR>
				<TD WIDTH="182" bgcolor="#FFFFFF" class="style1"><div align="left"><FONT FACE="Arial, Helvetica">Year:</FONT></div></TD>
				<TD WIDTH="180" bgcolor="#FFFFFF">					  <P align="left">
					  
				  <SELECT NAME=year onchange=showyear(this.options[this.selectedIndex].value)>
				    <?php 
               show_year($year);
            ?>
			      </SELECT>
					  
                  </TD>
			</TR>
			<TR>
			  <TD bgcolor="#ECECE7" class="style1"> </TD>
			  <TD bgcolor="#ECECE7"> </TD>
			  </TR>
			<TR>
				<TD WIDTH="182" bgcolor="#FFFFFF" class="style1"><div align="left"><FONT FACE="Arial, Helvetica">Manufacturer:</FONT></div></TD>
				<TD WIDTH="180" bgcolor="#FFFFFF">					  <P align="left">
				  <SELECT NAME=manufacture onchange=showmodel(this.options[this.selectedIndex].value,year.value)>
          
            <?php 
                show_manufactur($year,$man);
            ?>
				  </SELECT>

                  </TD>
			</TR>
			<TR>
			  <TD bgcolor="#ECECE7" class="style1"> </TD>
			  <TD bgcolor="#ECECE7"> </TD>
			  </TR>
			<TR>
				<TD WIDTH="182" bgcolor="#FFFFFF" class="style1"><div align="left"><FONT FACE="Arial, Helvetica">Model:</FONT></div></TD>
				<TD WIDTH="180" bgcolor="#FFFFFF">					  <P align="left">
				  <SELECT NAME=model >
					<?php 
               show_model($year,$man);
            ?>
				  </SELECT>

                  </TD>
			</TR>
			<TR>
			  <td colspan="2" bgcolor="#ECECE7"> </td>
			  </tr>
			<TR>
				<td colspan="2">
					<center>
					<p align="left"><input type="SUBMIT" name="searchtype" value="Search by YMM">
</center>					</td>
			</tr>
		</table>
</center>		</td>
  </tr>
</table>

</center>
<p>
</form>

 

 

MY DILEMMA:

I am trying to add two additional dropdown menus to this same form but I cannot get it to work.

 

The Non-Working Five Dropdown Code:

<?php
import_request_variables("gpc","");

function show_year($year) {
$year_arr = array("","1994","1995","1996","1997","1998");
$arr_size = count($year_arr);


for ($i = 0; $i < $arr_size; $i++) {
    if ($year_arr[$i] == $year)
       print "<option selected value=\"" .$year_arr[$i] ."\">".$year_arr[$i] ."</option>\n";
    else
       print "<option value=\"" .$year_arr[$i] ."\">".$year_arr[$i] ."</option>\n";
  }
}


function show_manufactur($year,$man)
{

//Result SQL statement
        $sql="SELECT MFR FROM " .$year. "data GROUP by MFR";

//Connect to server
require_once ("connect.php");

//Count the number of results
        $result = mysql_query("SELECT MFR FROM " .$year. "data GROUP by MFR");

        //$rows = mysql_result($result, 0, 'total');
        $rows = mysql_num_rows($result);

//Populate the drop down list
        $addblankspace = "";
        print "<option value=\"" .$addblankspace ."\">".$addblankspace ."</option>\n";
        for ($i = 0; $i < $rows; $i++)
        {
        $tempmfr = mysql_result($sql_result,$i,'MFR');

        if ($tempmfr == $man)
          print "<option selected value=\"" .$tempmfr."\">".$tempmfr."</option>\n";
        else
          print "<option value=\"" .$tempmfr ."\">".$tempmfr ."</option>\n";

        }
        $sql = "";
//Close the database connection
         mysql_close();
}

// Show Use Data By: Jonnel
// have no Idea the database Structure

function show_use($year,$man,$use)
{

//Result SQL statement
        $sql="SELECT * FROM " .$year. "data WHERE MFR = '" .$man. "' AND Use='" .$use. "'";

//Connect to server
require_once ("connect.php");

//Count the number of results
        $result = mysql_query("SELECT * FROM " .$year. "data WHERE MFR = '" .$man. "' AND Use='" .$use. "'");

        //$rows = mysql_result($result, 0, 'total');
        $rows = mysql_num_rows($result);

//Populate the drop down list
        $addblankspace = "";
        print "<option value=\"" .$addblankspace ."\">".$addblankspace ."</option>\n";
        for ($i = 0; $i < $rows; $i++)
        {
        $tempuse = mysql_result($sql_result,$i,'Use');

          print "<option value=\"" .$tempuse ."\">".$tempuse ."</option>\n";

        }
        $sql = "";
//Close the database connection
         mysql_close();
}


// Show Level Data By: Jonnel
// have no Idea the database Structure
function show_level($year,$man,$use,$level)
{

//Result SQL statement
        $sql="SELECT * FROM " .$year. "data WHERE MFR = '" .$man. "' AND Use='" .$use. "' AND Level = '" .$level. "'";

//Connect to server
require_once ("connect.php");

//Count the number of results
        $result = mysql_query("SELECT * FROM " .$year. "data WHERE MFR = '" .$man. "' AND Use='" .$use. "' AND Level = '" .$level. "'");

        $rows = mysql_num_rows($result);

//Populate the drop down list
        $addblankspace = "";
        print "<option value=\"" .$addblankspace ."\">".$addblankspace ."</option>\n";
        for ($i = 0; $i < $rows; $i++)
        {
        $templevel = mysql_result($sql_result,$i,'Level');

          print "<option value=\"" .$templevel ."\">".$templevel ."</option>\n";

        }
        $sql = "";
//Close the database connection
         mysql_close();

}


function show_model($year,$man,$use,$level)
{


//Result SQL statement
        $sql="SELECT * FROM " .$year. "data WHERE MFR = '" .$man. "' AND Use='" .$use. "' AND Level = '" .$level. "' GROUP by MODEL";

//Connect to server
require_once ("connect.php");

//Count the number of results
        $result = mysql_query("SELECT * FROM " .$year. "data WHERE MFR = '" .$man. "' AND Use='" .$use. "' AND Level = '" .$level. "' GROUP by MODEL");

        $rows = mysql_num_rows($result);

//Populate the drop down list
        for ($i = 0; $i < $rows; $i++)
        {
          $tempmfr = mysql_result($sql_result,$i,'MODEL');
          print "<option value=\"" .$tempmfr ."\">".$tempmfr ."</option>\n";
        }
        $sql = "";
//Close the database connection
         mysql_close();
}

?>


<script language=javascript>
function showyear(year)
{
  refresh = "./verdevdatabase.php?year=" + year;
  location.href=refresh;
}

function showmodel(man,year)
{
  refresh = "./verdevdatabase.php?man=" + man + "&year=" + year ;
  location.href=refresh;
}

function showuse(use,man,year)
{
  refresh = "./verdevdatabase.php?use = " "&man=" + man + "&year=" + year ;
  location.href=refresh;
}

</script>






<form action="verdevquery.php" method="POST" enctype="application/x-www-form-urlencoded">
  <center>
  <table width="375" border="0" align="left" cellpadding="0" cellspacing="0">
<TR>
  <TD><div align="left"><strong>Search by Engine Family Name:</strong></div></TD>
  </TR>
<TR>
  <TD><div align="center">
        <p align="left">
          <input name="efn" type="text" id="efn" size="25">
        </p>
    <p align="left">
      <input name="searchtype" type="submit" id="searchtype" value="Search by EFN" />
        </p>
    </div>
    <div align="left"></div></TD>
  </TR>
<TR>
  <TD> </TD>
  </TR>
<TR>
  <TD> </TD>
  </TR>
<TR>
  <TD> </TD>
  </TR>
<TR>
  <TD><div align="left"><strong>Browse by Year, Manufacture, Use, Level and Model:</strong></div></TD>
  </TR>
<TR>
	<TD WIDTH="375"><CENTER>


		<TABLE WIDTH="362" HEIGHT="139" BORDER="0" align="left" CELLPADDING="0" CELLSPACING="0">
			<TR>
				<TD WIDTH="182" bgcolor="#FFFFFF" class="style1"><div align="left">
				<FONT FACE="Arial, Helvetica">Year:</FONT></div></TD>
				<TD WIDTH="180" bgcolor="#FFFFFF">					  <P align="left">

				  <SELECT NAME=year onchange=showyear(this.options[this.selectedIndex].value)>
				    <?php
               show_year($year);
            ?>
			      </SELECT>

                  </TD>
			</TR>

			<TR>
			  <TD bgcolor="#ECECE7" class="style1"> </TD>
			  <TD bgcolor="#ECECE7"> </TD>
			  </TR>
			<TR>
				<TD WIDTH="182" bgcolor="#FFFFFF" class="style1">
				<div align="left"><FONT FACE="Arial, Helvetica">Manufacturer:</FONT></div></TD>
				<TD WIDTH="180" bgcolor="#FFFFFF">					  <P align="left">
				  <SELECT NAME=manufacture onchange=showmodel(this.options[this.selectedIndex].value,year.value)>

            <?php
                show_manufactur($year,$man);
            ?>
				  </SELECT>

                  </TD>
			</TR>

							<TR>
			  <TD bgcolor="#ECECE7" class="style1"> </TD>
			  <TD bgcolor="#ECECE7"> </TD>
			  </TR>
			<TR>
				<TD WIDTH="182" bgcolor="#FFFFFF" class="style1">
				<div align="left"><FONT FACE="Arial, Helvetica">Use:</FONT></div></TD>
				<TD WIDTH="180" bgcolor="#FFFFFF">					  <P align="left">
				  <SELECT NAME=use onchange=showuse(this.options[this.selectedIndex].value,manufacture.value,year.value)>

            <?php
                show_use($year,$man,$use);
            ?>
				  </SELECT>

                  </TD>
			</TR>

			<TR>
			  <TD bgcolor="#ECECE7" class="style1"> </TD>
			  <TD bgcolor="#ECECE7"> </TD>
			  </TR>
			<TR>
				<TD WIDTH="182" bgcolor="#FFFFFF" class="style1"><div align="left">
				<FONT FACE="Arial, Helvetica">Level:</FONT></div></TD>
				<TD WIDTH="180" bgcolor="#FFFFFF">					  <P align="left">
				  <SELECT NAME=level onchange=showlevel(this.options[this.selectedIndex].value,use.value,manufacture.value,year.value) >
		<?php
               show_level($year,$man,$use,$level);
            ?>
				  </SELECT>

                  </TD>
			</TR>



			<TR>
			  <TD bgcolor="#ECECE7" class="style1"> </TD>
			  <TD bgcolor="#ECECE7"> </TD>
			  </TR>
			<TR>
				<TD WIDTH="182" bgcolor="#FFFFFF" class="style1"><div align="left">
				<FONT FACE="Arial, Helvetica">Model:</FONT></div></TD>
				<TD WIDTH="180" bgcolor="#FFFFFF">					  <P align="left">
				  <SELECT NAME=model >
					<?php
               show_model($year,$man);
            ?>
				  </SELECT>

                  </TD>
			</TR>

			<TR>
			  <td colspan="2" bgcolor="#ECECE7"> </td>
			  </tr>
			<TR>
				<td colspan="2">
					<center>
					<p align="left"><input type="SUBMIT" name="searchtype" value="Search by YMM">
</center>					</td>
			</tr>
		</table>
</center>		</td>
  </tr>
</table>

</center>
<p>
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.