Need QUICK help from anyone with PHP knowledge!!!

by man5
6 replies
I have a problem that needs solving. I need you to take a look at my code.
pm me!!!
#knowledge #php #quick
  • Profile picture of the author Joe Crosbie
    Could you be more specific about what you need help with?

    Joe Crosbie,
    Signature
    I chose entrepreneurship over further education despite being laughed at by my friends and family..

    I recently hit the "RESTART" button on my life, read my personal blog to find out how I did it :)
    {{ DiscussionBoard.errors[8673234].message }}
  • Profile picture of the author RobinInTexas
    If your code is short, post it here, if its more than a dozen lines of so post it on pastebin.com and give us the pastebin link and someone might help you.
    Signature

    Robin



    ...Even if you're on the right track, you'll get run over if you just set there.
    {{ DiscussionBoard.errors[8674095].message }}
  • Profile picture of the author man5
    I solved all my problems except for 1.

    I created down downs for country, province, city. I can get the data from mysql database and even post the data back into the database. This all works perfectly. However, to turn these drop downs into dynamic dropdowns, I need the help of javascript. The tutorials i looked at helped me create a dynamic drop down with javascript. But if i use that method, i can not use a query to upload data into the database.

    So what would be the solution to this?
    Signature
    {{ DiscussionBoard.errors[8739256].message }}
    • Profile picture of the author Brandon Tanner
      Originally Posted by man5 View Post

      I solved all my problems except for 1.

      I created down downs for country, province, city. I can get the data from mysql database and even post the data back into the database. This all works perfectly. However, to turn these drop downs into dynamic dropdowns, I need the help of javascript. The tutorials i looked at helped me create a dynamic drop down with javascript. But if i use that method, i can not use a query to upload data into the database.

      So what would be the solution to this?
      If you're asking how to pass data between the browser and server (without having to refresh the page), then you can use Ajax for that. Look into jQuery's "post" method.

      jQuery.post() | jQuery API Documentation
      Signature

      {{ DiscussionBoard.errors[8739403].message }}
      • Profile picture of the author man5
        Originally Posted by Brandon Tanner View Post

        If you're asking how to pass data between the browser and server (without having to refresh the page), then you can use Ajax for that. Look into jQuery's "post" method.

        jQuery.post() | jQuery API Documentation

        Actually that's not what i mean.

        Here is the js code for a dynamic drop down. My question is, how do I get the country/province/city data to upload to the database? It's not working using a query function. Am I doing something wrong?

        Code:
        var SList = new Object();  // JS object that stores data for options
        
        // HERE replace the value with the text you want to be displayed near Select
        var txtsl2 = '';
        
        /*
         Property with options for the Second select list
         The key in this object must be the same with the values of the options added in the first select
         The values in the array associated to each key represent options of the seccond select
        */
        SList.city = {
        "Alberta": ['Banff/Canmore', 'Calgary', 'Edmonton Area', 'Fort McMurray', 'Grande Prairie', 'Lethbridge', 'Lloydminster', 'Medicine Hat', 'Red Deer'],
        
        "British Columbia": ['Cariboo Area', 'Comox Valley Area', 'Cowichan Valley/Duncan', 'Cranbrook', 'Fraser Valley', 'Kamloops', 'Kelowna', 'Nanaimo', 'Nelson', 'Peace River Area', 'Port Alberni/Oceanside', 'Port Hardy/Port McNeill', 'Powell River District', 'Prince George', 'Revelstoke', 'Skeena-Bulkley Area', 'Sunshine Coast', 'Vancouver', 'Vernon', 'Victoria', 'Whistler'],
            
        "Manitoba": ['Brandon Area', 'Flin Flon', 'Thompson', 'Winnipeg'],
            
        "New Brunswick": ['Bathurst', 'Edmundston', 'Fredericton', 'Miramichi', 'Moncton', 'Saint John'],
        
        "Newfoundland": ['Corner Brook', 'Gander', 'Labrador', 'St. John\'s'],
            
        "Northwest Territories": ['Yellowknife'],    
            
        "Nova Scotia": ['Annapolis Valley', 'Bridgewater', 'Cape Breton', 'Halifax', 'New Glasgow', 'Truro', 'Yarmouth'],
            
        "Nunavut": ['Iqaluit'],
        
        "Ontario": ['Barrie', 'Belleville Area', 'Brantford', 'Brockville', 'Chatham-Kent', 'Cornwall', 'Guelph', 'Hamilton', 'Kapuskasing', 'Kenora', 'Kingston Area', 'Kitchener Area', 'Leamington', 'London', 'Muskoka', 'Norfolk County', 'North Bay', 'Ottawa/Gatineau Area', 'Owen Sound', 'Peterborough', 'Renfrew County Area', 'Sarnia Area', 'Sault Ste. Marie', 'St. Catharines', 'Sudbury', 'Thunder Bay', 'Timmins', 'Toronto(GTA)', 'Windsor Region', 'Woodstock'],
            
        "Prince Edward Island": ['Charlottetown', 'Summerside'],    
            
        "Quebec": ['Abitibi-Temiscamingue', 'Baie-Comeau', 'Centre-du-Quebec', 'Chaudiere-Appalaches', 'Chibougamau/Northern Quebec', 'Gaspe', 'Granby', 'Lanaudiere', 'Mauricie', 'Montreal', 'Quebec City', 'Rimouski/Bas-St-Laurent', 'Saguenay-Lac-Saint-Jean', 'Saint-Hyacinthe', 'Saint-Jean-sur-Richelieu', 'Sept-Iles'],    
            
        "Saskatchewan": ['La Ronge', 'Meadow Lake', 'Nipawin', 'Prince Albert', 'Regina Area', 'Saskatoon', 'Swift Current'],    
        
        "Yukon": ['Whitehorse']
            
        };
        
        
        // function to get the dropdown list
        
        SList.getSelect = function(slist, option) {
          if(SList[slist][option]) {
            if(slist == 'city') {
              var addata = '';
              for(var i=0; i<SList[slist][option].length; i++) {
                addata += '<option value="'+SList[slist][option][i]+'">'+SList[slist][option][i]+'</option>';
              }
        
              document.getElementById('city').innerHTML = txtsl2+' <select name="city">'+addata+'</select>';
            }
          }
          else if(slist == 'city') {
            // empty the tag for 2nd select list
            document.getElementById('city').innerHTML = '';
          }
        }
        Now the other method I have is, having the country/provinces/cities in the database table. I can use a query GET function to get those lists and echo them in the dropdown. I can use insert these fields back into the database table that I have set up. It works like a charm.
        The only thing left to do is turning these 3 drop downs into dynamic drop downs. For example, I choose a province and the dropdown below it will appear with relevant cities to that province. This can only be two with Javascript as far as I know.
        The above code is my javascript code that does that. But that won't insert data into the database table.
        Signature
        {{ DiscussionBoard.errors[8740414].message }}
  • Profile picture of the author ClicProject
    Well, using your script above to create the dropdowns, you can tell which city/country has been selected when the form is submitted from the $_POST data, then you can do whatever you want with the data, such as insert it into your customer order table etc.

    If you are going to populate the dropdowns from the database using AJAX, you need to store a relationship between the country/province/city/

    Eg:
    table cities:

    id
    name
    province_id

    table provinces

    id
    name
    country_id

    table countries

    id
    name


    That way, when you select a country in the dropdown, you would use ajax to call a script that loads all the provinces from the provinces table with the selected country_id, and populates your second dropdown.

    Then, when they select the province, you would do another ajax call to populate the final dropdown from the cities table, selecting all cities with the selected province_id.

    Then, when the form submits, you have a value for the country, province and city in the post data.

    Does that answer your question?
    {{ DiscussionBoard.errors[8742052].message }}

Trending Topics