Jump to content

flat file array or mysql db for auto complete script?


acctman

Recommended Posts

i'm trying to setup an auto complete script this is an example of it pulling from a array. how can i pull from a database in real time? right now the GET request to the array is done in real time but would a db be more faster when i have about 1000+ cities ?

 

<?php

 

$q = strtolower($_GET["q"]);

if (!$q) return;

$items = array(

"Great <em>Bittern</em>"=>"Botaurus stellaris",

"Little <em>Grebe</em>"=>"Tachybaptus ruficollis",

"Black-necked Grebe"=>"Podiceps nigricollis",

"Little Bittern"=>"Ixobrychus minutus",

"Black-crowned Night Heron"=>"Nycticorax nycticorax",

"Purple Heron"=>"Ardea purpurea",

"White Stork"=>"Ciconia ciconia",

"Spoonbill"=>"Platalea leucorodia",

"Red-crested Pochard"=>"Netta rufina",

"Common Eider"=>"Somateria mollissima",

"Red Kite"=>"Milvus milvus",

"Solitary Sandpiper"=>"Tringa solitaria",

"Heuglin's Gull"=>"Larus heuglini"

);

 

foreach ($items as $key=>$value) {

    if (strpos(strtolower($key), $q) !== false) {

        echo "$key|$value\n";

    }

}

 

?>

[code=php:0]

Link to comment
Share on other sites

Pulling from a database would require a lot of overhead processing the queries.

 

You might want to make a automated script that pulls from the database and caches it into a script every 5 minutes or so.

 

You would not want to use a database if you arent using a persistent connection.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.