开发者

give preference to print array values in php

开发者 https://www.devze.com 2022-12-29 16:02 出处:网络
I have country table, i fetch all values and moved into array , these value i like to populate into combo/dropdown list ,

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 pref开发者_C百科erence ,

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


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号