使用mysql显示特定国家/地区的Web内容的最佳方式(Best way to display web content for specific country using mysql)
需要你的帮助。 我需要你们所有善良人士的建议。
我有一些内容,我只需要显示给几个国家。我可以通过Geoip.i将我的内容存储在MySQL数据库中,并使用country_code field.country代码可以为空或任何单个代码或组逗号分隔值
我想做的是,
- 检查country_code,如果为空,则显示所有用户的内容。
- 如果country_code不为空并且只有一个值,则仅显示给定country_code用户的内容。
- 如果country_code是逗号分隔值组,则显示所有逗号分隔的国家/地区用户的内容。
我有两种方法可以做到这一点
分别为
each
国家/地区添加数据列并显示内容,例如美国,英国,澳大利亚三个国家/地区的three columns
,如果用户的位置为美国,
$sql=mysql_fetch_array(mysql_query("SELECT * FROM content_table WHERE US=='$country_code'"))
;将单列的国家/地区数据添加为country_code并存储美国,英国,澳大利亚,如果用户的位置为美国,
$sql=mysql_fetch_array(mysql_query("SELECT * FROM content_table WHERE country_code!=''")); $pieces = explode(",", $sql['country_code']); foreach($pieces as $val){ if($country_code=="US") //display content }
注意: 国家数量可能根据我的需要而有所不同
什么是克服这一点的最佳做法,
- 使用不同的列到不同的国家进行快速搜索,但我认为添加更多的列是不好的
- 使用单列和迭代逗号分隔值需要更多计算
我该怎么办..?? 请告诉我这个..或者你有什么想法比这更好..? 谢谢
Need a big help from you. I need an advice from all you good people out there.
I have some contents that i need to display only to few countries.I am okay with getting the user's country with Geoip.i am storing my content in MySQL database with a country_code field.country code can be empty or any single code or group of comma separated values
What i want to do is,
- checking country_code and if it is empty, display that content for all users.
- if country_code is not empty and only a single value,display content only for the given country_code users.
- if country_code is group of comma separated values,display contents for all the comma separated country users.
i have two options for do this
adding data columns for
each
country separately and display contents as for examplethree columns
for three countries US,UK,AU and if user's location is US,
$sql=mysql_fetch_array(mysql_query("SELECT * FROM content_table WHERE US=='$country_code'"))
;adding country data for single column as country_code and store US,UK,AU and if user's location is US,
$sql=mysql_fetch_array(mysql_query("SELECT * FROM content_table WHERE country_code!=''")); $pieces = explode(",", $sql['country_code']); foreach($pieces as $val){ if($country_code=="US") //display content }
NOTE:amount of countries may differs according to my needs
what will be the best practice to overcome this,
- using different columns to different country make fast search but adding more columns is not good i think
- using single column and iterate comma separated values needs more computation
What should i do..?? please advice me on this.. OR do you have any idea better than this..? Thanks
满意答案
$sql=mysql_fetch_array(mysql_query("SELECT * FROM content_table WHERE country_code = '' OR country_code REGEXP ',?". $user_country_code .",?'"));
如果我理解你,只有当用户国家代码在
country_code
字段中或者未指定country_code
,您才想向用户显示元素?即使数据库解决方案更好,也应该这样做。
$sql=mysql_fetch_array(mysql_query("SELECT * FROM content_table WHERE country_code = '' OR country_code REGEXP ',?". $user_country_code .",?'"));
If I understood you well, you want to show elements to the user only if the user country code is in the
country_code
field or if thecountry_code
is not specified ?This should do it, even if a database solution would be better.
相关问答
更多指向相同内容的国家/地区特定URL是否可能?(Country-specific URLs pointing to the same content, is it possible?)
有什么数据库专业书籍介绍?
不同的内容取决于具有相同URL的国家/地区(Different content depending on the country with the same URL)
如何制作国家特定网站(和内容)?(How to make Country - Specific Web Site (and contents)? [closed])
Google地方信息只能从特定国家/地区自动完成和组件限制搜索?(Google Places how to autocomplete and componentRestrictions search only from a specific country?)
自动填充仅显示特定国家/地区或邮政编码的结果(autocomplete display only results from specific country or zip code)
Bluehost MySQL国家/地区特定字符编码(Bluehost MySQL Country Specific Characters Encoding)
显示Web内容标题而不是“Web内容显示”(Display Web Content Title instead of “Web Content Display”)
跨会话的用户特定内容建议[MySQL / Web](user-specific content suggestions across sessions [MySQL/Web])
使用mysql显示特定国家/地区的Web内容的最佳方式(Best way to display web content for specific country using mysql)
相关文章
更多Shiro整合到Web应用
《Web开发的平民英雄:PHP+MySQL》扫描版[PDF]
Web scraper open source
Solr与Mysql集成指南
JAVA WEB
web storm使用和配置
Solr与Mysql集成指南
关于 style="display:none" 得问题
mysql问题
MySql 查询语句中包含中文时不能查询结果 编码问题!
最新问答
更多Python / IPython奇怪的不可重现列表索引超出范围错误(Python/IPython strange non reproducible list index out of range error)
故事板从表格单元中延伸出来并显示其详细信息披露按钮(storyboard segue from a tablecell an its Detail Disclosure Button)
我们可以将Gherkin功能文件与testcomplete集成(Can we integrate Gherkin feature files with testcomplete)
TrustAllCertificatesCallback被忽略(TrustAllCertificatesCallback is ignored)
返回嵌套元素的索引(Return index of nested element)
在数组中重新编号元素的有效方法(Efficient way of re-numbering elements in an array)
Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)
Javascript错误:未捕获TypeError:无法读取null的属性'value'[duplicate](Javascript error: Uncaught TypeError: Cannot read property 'value' of null [duplicate])
使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)
如何让XMLSerializer将命名空间添加到嵌套对象中的属性?(How do I get the XMLSerializer to add namespaces to attributes in nested objects?)
Copyright ©2023 656463.com All Rights Reserved.滇ICP备2022006988号-50
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们,本站将尽快处理。谢谢合作!