Jump to content

Populating the drop down and pressing the Submit button


suttercain

Recommended Posts

Hi everyone,

 

I've got two issues I am dealing with right now.

 

1. The first is I have two drop down menus. The first is "year" and the second is "mfr". When a user selects a year from the drop down it then populates the second drop down, mfr, from the MySQL database. Theat is working fine. But the problem I am having is the "submit" button (which I have labeled as "browse"). When I click it. Nothing happens, no action tacks place. I have looked over the code and I can't figure it out. (See Code Box 1 Below).

 

2. Right now the "mfr" drop down is populated by the MySQL database and reads with a list like "Acr", "Alp", etc. These are abreviations. I need to set up an array to have them instead read the entire mfr name. Example: Instead of "Acr" it needs to be "Acura". Instead of "Alp" it needs to be "Alpine". I need these full names to appear in the drop down. I know I need to do something like this (See Code Box 2 Below) but I can't get my finger on it.

 

CODE BOX 1

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

function show_year($year) {
$year_arr = array("","2007");
$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. "ccvl GROUP by division";

//Connect to the Database via the Include File!
require ('get_connected.php');

//Count the number of results
        $result = mysql_query("SELECT * FROM " .$year. "ccvl GROUP by division");
        
        //$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,'division');
        
        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();
}


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

<body>
<FORM ACTION=dropdownquery.php" METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
  <CENTER>
</CENTER>
</FORM>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><strong>Browse by Year and Manufacturer</strong></td>
  </tr>
  <tr>
    <td>
      <table width="257" height="139" border="0" align="left" cellpadding="0" cellspacing="0">
        <tr>
          <td width="133"><font face="Arial, Helvetica">Year:</font></td>
          <td width="103"><p align="left">
              <select name="select" onChange="showyear(this.options[this.selectedIndex].value)">
                <?php 
               show_year($year);
            ?>
              </select>
          </p></td>
        </tr>
        <tr>
          <td width="133"><font face="Arial, Helvetica">Manufacturer:</font></td>
          <td width="103"><p align="left">
              <select name="select" onChange="showmodel(this.options[this.selectedIndex].value,year.value)">
                <?php 
                show_manufactur($year,$man);
            ?>
              </select>
          </p></td>
        </tr>
        <tr>
          <td colspan="2"><center>
              <p align="left">
                <input type="submit" name="searchtype" value="BROWSE" />
              </p>
          </center></td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td> </td>
  </tr>
</table>

 

 

CODE BOX 2

<?php 
// Convert the Array DIVISION to Full Names
$makes = array('ACUR'=>'ACURA', 
		   'ALP'=>'ALPINA', 
		   'ASMA'=>'ASTON MARTIN LAGONDA',
		   'AUDI'=>'AUDI',
		   'BAF'=>'FORD BAF CNG',
		   'BAYT'=>'GENERAL MOTORS BAYTECH CNG',
		   'BENT'=>'BENTLY',
		   'BMW'=>'BMW',
		   'BUIC'=>'BUICK',
		   'CAD'=>'CADILLAC',
		   'CHEV'=>'CHEVROLET',
		   'CHRS'=>'CHRYSLER',
		   'CUMM'=>'CUMMINS',
		   'DODG'=>'DODGE'
		   );
print $makes[$row['division']];
?>

 

 

Any help or suggestions would be greatly appreciated.

 

Thanks.

<?php 
// Convert the Array DIVISION to Full Names
$makes = array('ACUR'=>'ACURA', 
		   'ALP'=>'ALPINA', 
		   'ASMA'=>'ASTON MARTIN LAGONDA',
		   'AUDI'=>'AUDI',
		   'BAF'=>'FORD BAF CNG',
		   'BAYT'=>'GENERAL MOTORS BAYTECH CNG',
		   'BENT'=>'BENTLY',
		   'BMW'=>'BMW',
		   'BUIC'=>'BUICK',
		   'CAD'=>'CADILLAC',
		   'CHEV'=>'CHEVROLET',
		   'CHRS'=>'CHRYSLER',
		   'CUMM'=>'CUMMINS',
		   'DODG'=>'DODGE'
		   );
print $makes[strtoupper($row['division'])];
?>

 

http://us2.php.net/manual/en/function.strtoupper.php

 

Make sure the data coming out of the DB is in uppercase as PHP is case SenSitIve

I am not sure where you want this put but maybe this is how:

 

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

// Convert the Array DIVISION to Full Names
$makes = array('ACUR'=>'ACURA', 
		   'ALP'=>'ALPINA', 
		   'ASMA'=>'ASTON MARTIN LAGONDA',
		   'AUDI'=>'AUDI',
		   'BAF'=>'FORD BAF CNG',
		   'BAYT'=>'GENERAL MOTORS BAYTECH CNG',
		   'BENT'=>'BENTLY',
		   'BMW'=>'BMW',
		   'BUIC'=>'BUICK',
		   'CAD'=>'CADILLAC',
		   'CHEV'=>'CHEVROLET',
		   'CHRS'=>'CHRYSLER',
		   'CUMM'=>'CUMMINS',
		   'DODG'=>'DODGE'
		   );

function show_year($year) {
$year_arr = array("","2007");
$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)
{
global $makes; // edited here
//Result SQL statement        
        $sql="SELECT * FROM " .$year. "ccvl GROUP by division";

//Connect to the Database via the Include File!
require ('get_connected.php');

//Count the number of results
        $result = mysql_query("SELECT * FROM " .$year. "ccvl GROUP by division");
        
        //$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,'division');
        
        if ($tempmfr == $man) 
          print "<option selected value=\"" .$tempmfr."\">".$makes[$tempmfr]."</option>\n"; // edited here
        else 
          print "<option value=\"" .$tempmfr ."\">".$tempmfr ."</option>\n";
        }  
        $sql = "";
//Close the database connection
         mysql_close();
}


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

<body>
<FORM ACTION=dropdownquery.php" METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
  <CENTER>
</CENTER>
</FORM>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><strong>Browse by Year and Manufacturer</strong></td>
  </tr>
  <tr>
    <td>
      <table width="257" height="139" border="0" align="left" cellpadding="0" cellspacing="0">
        <tr>
          <td width="133"><font face="Arial, Helvetica">Year:</font></td>
          <td width="103"><p align="left">
              <select name="select" onChange="showyear(this.options[this.selectedIndex].value)">
                <?php 
               show_year($year);
            ?>
              </select>
          </p></td>
        </tr>
        <tr>
          <td width="133"><font face="Arial, Helvetica">Manufacturer:</font></td>
          <td width="103"><p align="left">
              <select name="select" onChange="showmodel(this.options[this.selectedIndex].value,year.value)">
                <?php 
                show_manufactur($year,$man);
            ?>
              </select>
          </p></td>
        </tr>
        <tr>
          <td colspan="2"><center>
              <p align="left">
                <input type="submit" name="searchtype" value="BROWSE" />
              </p>
          </center></td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td> </td>
  </tr>
</table>

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.