Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

Set up an autocomplete linked to a database

  • 22-03-2015 8:02am
    #1
    Banned (with Prison Access) Posts: 1,279 ✭✭✭


    Hi I was wondering is it possible to link an autocomplete to a database. I don't mind using php but i'd prefer to just use html and javascript.


Comments

  • Registered Users Posts: 10,455 ✭✭✭✭28064212


    You can't link to a database without having a server-side language (e.g. PHP) in the mix somewhere

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, and dark mode). Now available through the extension stores

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Registered Users Posts: 5,995 ✭✭✭Talisman


    28064212 wrote: »
    You can't link to a database without having a server-side language (e.g. PHP) in the mix somewhere
    In the 21st century, JavaScript is a server side language.


  • Registered Users Posts: 10,455 ✭✭✭✭28064212


    Talisman wrote: »
    In the 21st century, JavaScript is a server side language.
    I made the not-unreasonable assumption that someone referring to just using "html and javascript" was specifying client-side Javascript. I don't think introducing the concept of server-side Javascript is going to be helpful at this stage

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, and dark mode). Now available through the extension stores

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Registered Users Posts: 5,995 ✭✭✭Talisman


    kidneyfan wrote: »
    Hi I was wondering is it possible to link an autocomplete to a database. I don't mind using php but i'd prefer to just use html and javascript.
    How big a database are you dealing with? And how frequently is it updated?

    It's possible to implement the autocomplete functionality using a JSON file as the data source. This would negate the need for the database query apart from generating the JSON content. The mileage you get from this approach would be dependent on the size of the data used as all the work would be done on the client side.


  • Banned (with Prison Access) Posts: 1,279 ✭✭✭kidneyfan


    28064212 wrote: »
    I made the not-unreasonable assumption that someone referring to just using "html and javascript" was specifying client-side Javascript. I don't think introducing the concept of server-side Javascript is going to be helpful at this stage
    I think that was a reasonable assumption. In fact the question was poorly phrased and that poor phrasing arose from a lack of proper research on my part.

    Essentially I want to ensure that phonegap will compile my little web app. Phonegap specify html and javascript. I think that they mean client side javascript. It is a bit of a pity as it means that updating autocompletes etc. will require a new build.

    Server side Javascript looks very interesting.


  • Advertisement
  • Banned (with Prison Access) Posts: 1,279 ✭✭✭kidneyfan


    Talisman wrote: »
    How big a database are you dealing with? And how frequently is it updated?

    It's possible to implement the autocomplete functionality using a JSON file as the data source. This would negate the need for the database query apart from generating the JSON content. The mileage you get from this approach would be dependent on the size of the data used as all the work would be done on the client side.

    Thanks Talisman.
    The database is small. 30,000 core records. With maybe 100,000 in total for any 1 implementation.

    Thanks for drawing my attention to server side Javascript.


  • Registered Users Posts: 2,029 ✭✭✭colm_c


    kidneyfan wrote: »
    I think that was a reasonable assumption. In fact the question was poorly phrased and that poor phrasing arose from a lack of proper research on my part.

    Essentially I want to ensure that phonegap will compile my little web app. Phonegap specify html and javascript. I think that they mean client side javascript. It is a bit of a pity as it means that updating autocompletes etc. will require a new build.

    Server side Javascript looks very interesting.

    This is bit of a different question.

    Is your database local on the app/device -- in which case you'll need to use a database plugin such as openDatabase: http://docs.phonegap.com/en/edge/cordova_storage_storage.opendatabase.md.html

    Although it might choke with that amount of data being loaded/queried.

    If your database is to be remotely hosted -- then you're setting up a client/server architecture, in which case you need to use some server-side language to setup a REST api backed by a DB. You should also look at security and data integrity as part of that. Can be done in NodeJS/Ruby/PHP etc. handy enough.

    You may also need to look at indexes and setting up search on the database to ensure you're query comes back in appropriate time. This applies to an app database and a server too.


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Talisman wrote: »
    In the 21st century, JavaScript is a server side language.
    In the 20th century, JavaScript was a server side language. However, as 28064212 pointed out, when someone starts talking about "html and javascript", theyr'e almost certainly referring to client-side development (although HTML used to be used as a sever-side language too).

    As to how to do it, as has been said, it would involve a client-side asycanous call to the server, triggered by something like an onchange event in the text box, which in turn would pull the data out using a server-side script and return it in a format that can be easily parsed by the client (JSON, most likely).

    JavaScript can be used for the server-side part of the solution, but this means that the server must support it. It may be less hassle to use something more common like PHP for this.

    Here's a tutorial / implementation using PHP:

    http://www.pontikis.net/blog/jquery-ui-autocomplete-step-by-step

    And how to connect to a database using server-side Javascript, if you want to replace the PHP above with a JavaScript implementation:

    http://stackoverflow.com/questions/857670/how-to-connect-to-sql-server-database-from-javascript

    Come to think of it, I should probably ask what the database is too.


Advertisement