Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9219179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:03:07+00:00 2026-06-18T03:03:07+00:00

I am implementing the geonames webservice, like this: $( #loc_from ).autocomplete({ source: function( request,

  • 0

I am implementing the geonames webservice, like this:

$( "#loc_from" ).autocomplete({
    source: function( request, response ) {
        $.ajax({
            url: "http://ws.geonames.org/searchJSON",
            dataType: "jsonp",
            data: {
                featureClass: "P",
                style: "full",
                maxRows: 12,
                name_startsWith: request.term,
                searchlang: 'ES'
            },
            success: function( data ) {
                response( $.map( data.geonames, function( item ) {
                    item.label = item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName;
                    return item;
                }));
            }
        });
    },
    minLength: 2,
    select: function( event, ui ) {
         ui.item.task = 'new_city';
         $.post('/includes/router.php', ui.item , function(){

         });
         $('#id_loc').val(ui.item.gid);
         //alert(ui.item.gid);
    }
});

where in router.php I have:

case 'new_city':
    /* comprobar si exite */
    $query = "SELECT geonameid FROM geonames";
    if(count(cache_query($query))>0){
        /* Its already in my database */
    }else{
        foreach ($_POST as $key => $value) {
                    check_field($key);
            echo $key.': '.$value.'<br>';
        }
    }
    /* si no existe, dar de alta*/
    break;

So I would like the function check_field($key) to check if the geonames.$key field exists and alter the table and add it.

Is that posible? ( Also, Do you recommend this? )

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:03:08+00:00Added an answer on June 18, 2026 at 3:03 am

    I think you are looking for this

    SELECT * 
    FROM information_schema.COLUMNS 
    WHERE TABLE_SCHEMA = 'db_name' 
    AND TABLE_NAME = 'geonames' 
    AND COLUMN_NAME = 'column_name'
    

    From PHP you can do this

    function add_column_if_not_exist($db, $column, $column_attr = "VARCHAR( 255 ) NULL" ){
        $exists = false;
        $columns = mysql_query("show columns from $db");
        while($c = mysql_fetch_assoc($columns)){
            if($c['Field'] == $column){
                $exists = true;
                break;
            }
        }      
        if(!$exists){
            mysql_query("ALTER TABLE `$db` ADD `$column`  $column_attr");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While implementing Multithreaded Cache, i found this article on MSDN. http://msdn.microsoft.com/en-us/library/system.threading.readerwriterlockslim.aspx This is for
When implementing move constructors and move assignment operators, one often writes code like this:
implementing publishActivity in PHP using the REST API using this code: $activity = array(
when implementing a recursive function during development, i will use a counter and exit
When implementing a hash table using a good hash function (one where the probability
implementing service something similar with tinyurl or bit.ly, I'm would like to expose service
Im implementing NFS and almoste done but the RFC section 3.3.8 says this in
I'm implementing a client consuming a webservice. I want to reduce dependencies and decided
Implementing a web service that uses Transport-level security with WCF over HTTP is pretty
Implementing/handling idempotency in c# with Jolivers EventStore. Does this mean just taking care of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.