Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

Drop down menu using php and mysql database

Javascript coding ..

Moderators: macek, egami, gesf

Postby jbr » Tue Feb 15, 2005 6:05 pm

Hi

I know you don't want to do this in javascript, it would be to much data to load!

First you need to design the logic!

1. database

You could do this with one table or more, it really depends on how you want to do it! Using more than one table will help if your service get big!

But let me get you started with a simple setup!

Lets say you are using (1) table!

columns!

id auto incre... int 10
zip_postal vchar 7
city_place vchar 40
state_prov vchar 40
country_long vchar 60
country_short char 2
biz_type vchar 255
sec_type vchar 255
.... -> other stuff -> phone, addess, hours open and so on!


Now when your page loads, you just check if a request has been passed via a query or form process, if not load the default select boxes

Code: Select all

<?

if ( isset ( $_REQUEST['next'] ) )
{
// a request has been sent, load what the request wants!
}
else
{
// no request, load the default
}



This is a very basic way to do this!

Now the backend would look like this!

example for US states select box!

Code: Select all

   function state_box ()
   {

      $sd = "al,Alabama|ak,Alaska|az,Arizona|ar,Arkansas|as,American Samoa|ca,California|co,Colorado|ct,Connecticut|de,Delaware|dc,District of Columbia|fl,Florida|fm,FS of Micro|ga,Georgia|gu,Guam|hi,Hawaii|id,Idaho|il,Illinois|in,Indiana|ia,Iowa|ks,Kansas|ky,Kentucky|la,Louisiana|me,Maine|mp,Mariana Islands|mh,Marshall Islands|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|pw,Palau|pa,Pennsylvania|pr,Puerto Rico|ri,Rhode Island|sc,South Carolina|sd,South Dakota|tn,Tennessee|tx,Texas|ut,Utah|vt,Vermont|va,Virginia|vi,Virgin Islands|wa,Washington|wv,West Virginia|wi,Wisconsin|wy,Wyoming";

      $ssd = explode ( '|', $sd );


      $sbox = "<select name='sf' size='5'>";

      for ( $i = 0; $i < sizeof ( $ssd ); $i++ )
      {

         $st = ( $i == '0' ) ? ' selected' : '';

         $ops = explode ( ',', $ssd[$i] );

         $sbox .= '<option value="' . $ops[0] . '"' . $st . '> ' . $ops[1];

      }

         return ( $sbox . '</select>' );

   }




I have some script examples that will show you how to do this in full detail, including the database lookups to the page output! Just PM me and I will give the scripts!

You can see an example here!

Click on the "Find Button" on any of these pages to see how the select box lookups work!


http://zip.ya-right.com/distance/us/city.php


c, ya...

jbr
jbr
New php-forum User
New php-forum User
 
Posts: 6
Joined: Tue Feb 15, 2005 3:55 pm

Return to JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.