views:

59

answers:

2

Hi ,

I have country table,

i fetch all values and moved into array ,

these value i like to populate into combo/dropdown list ,

here i want to do some magic things,

that is , for my site most of the users coming from uk,us,Australia,Romain and few,

So i like to populate by my preference ,

is there any array will do this magic work, else is it possible mysql query ,

So final question is ,

Populate country name into combo based on my prefernce ,

Thanks

+4  A: 

The preference can't be auto-generated I wouldn't have thought since there is no way to know. What I would do is have a (numeric) preference value in the table along with the country, then when you do the SQL query, order it by the preference field. You could also increment this field each time a user picks that country so the order of the list changes based on the most common locations of your audience.

Gazler
Yes i will do this here after ..But my past data's dont have such increment fields,How can i do this...but i have customer hit table, in that,i have entries of each customer country code,is it possible do some magic things,that is any join query somthing
Bharanikumar
Not 100% on the syntax of it. But it would be something like "insert into countries(preference) values(select count(*) from hits where hits.country = countries.country)"
Gazler
+1  A: 

It's very annoying to have a country list where not all items can be found at their alphabetical position. I suggest you just duplicate the top 2 or 3 more used items and show them at the top of the complete list:

Australia
United Kingdom
United States
---------------
Afghanistan
Albania
Australia
Austria
...

I'm not sure, though, why you think this involves any sort of magic. You could accomplish this by adding a new weight column to the country table in your database that defaults to e.g. 1 and increment it to larger values for items you want to highlight. You can then build your data in PHP or in SQL.

SELECT country_id, country_name
FROM country
WHERE weight>1
ORDER BY weight, country_name
UNION ALL
SELECT country_id, country_name
FROM country
ORDER BY country_name
Álvaro G. Vicario
i dont have weght such column..but i have customer table, in that i have the fieldname like customer_contact no,this field contain the country-mobile or landline number...
Bharanikumar
Not being allowed to alter the database is an important pre-requisite. You should have mentioned it in the question.
Álvaro G. Vicario
yes,, am not mentioned,,,
Bharanikumar