Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

zone_name instead of zone_id


Guest

Recommended Posts

I'm trying to use the state pull down menu code from `create_account.php` on a simple name and address form, but the form is returning the `zone_id` instead of the `zone_name`. Can anyone see a way to pull the `zone_name` from the array, instead of the `zone_id`?

 

This is the section of the form which asks for the 'state'.

 

<?php	$zones_array = array();
       $zones_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));
       $zones_query = tep_db_query("select [b]zone_id[/b], [b]zone_name[/b] from " . TABLE_ZONES . " where zone_status='1' and zone_country_id = '223' order by zone_name");
       while ($zones_values = tep_db_fetch_array($zones_query)) {
         [b]$zones_array[/b][] = array('id' => $zones_values['zone_id'], 'text' => $zones_values['zone_name']);
       }
?>                  <tr>
                     <td class="main" align="right"><?php echo REQUEST_STATE; ?></td>
                     <td class="main"><?php echo tep_draw_pull_down_menu([b]'state', $zones_array[/b]) . ' ' . (tep_not_null(ENTRY_STATE_TEXT) ? '<span class="inputRequirement">' . ENTRY_STATE_TEXT . '</span>': ''); ?></td>
                   </tr>

 

It returns 43 instead of New York, so we get:

FirstName:John

LastName:Doe

Address:1 Main St

City:Anytown

State:43

Zip:10011

...but we want:

FirstName:John

LastName:Doe

Address:1 Main St

City:Anytown

State:New York

Zip:10011

Link to comment
Share on other sites

Here's a snippet that creates a state dropdown menu independent from the zones table...

 

$states_arr = array('AL'=>"Alabama",'AK'=>"Alaska",'AZ'=>"Arizona",'AR'=>"Arkansas",'CA'=>"California",'CO'=>"Colorado",'CT'=>"Connecticut",'DE'=>"Delaware",'DC'=>"District Of Columbia",'FL'=>"Florida",'GA'=>"Georgia",'HI'=>"Hawaii",'ID'=>"Idaho",'IL'=>"Illinois",'IN'=>"Indiana",'IA'=>"Iowa",'KS'=>"Kansas",'KY'=>"Kentucky",'LA'=>"Louisiana",'ME'=>"Maine",'MD'=>"Maryland",'MA'=>"Massachusetts",'MI'=>"Michigan",'MN'=>"Minnesota",'MS'=>"Mississippi",'MO'=>"Missouri",'MT'=>"Montana",'NE'=>"Nebraska",'NV'=>"Nevada",'NH'=>"New Hampshire",'NJ'=>"New Jersey",'NM'=>"New Mexico",'NY'=>"New York",'NC'=>"North Carolina",'ND'=>"North Dakota",'OH'=>"Ohio",'OK'=>"Oklahoma",'OR'=>"Oregon",'PA'=>"Pennsylvania",'RI'=>"Rhode Island",'SC'=>"South Carolina",'SD'=>"South Dakota",'TN'=>"Tennessee",'TX'=>"Texas",'UT'=>"Utah",'VT'=>"Vermont",'VA'=>"Virginia",'WA'=>"Washington",'WV'=>"West Virginia",'WI'=>"Wisconsin",'WY'=>"Wyoming");
   function showOptionsDrop($array){
       $string = '';
       foreach($array as $k => $v){
           $string .= '<option value="'.$k.'"'.$s.'>'.$v.'</option>'."\n";
       }
       return $string;
   }

<!-- state drop down menu  //-->
     <td class="main">
       <select name="state">
         <option value="0">Choose a state</option>
         <?php echo showOptionsDrop($states_arr); ?>
      </select>
      <?php echo (tep_not_null(ENTRY_STATE_TEXT) ? '<span class="inputRequirement">' . ENTRY_STATE_TEXT . '</span>': ''); ?>
      </td>

 

Hope this helps somebody. :thumbsup:

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...