使用mysql显示特定国家/地区的Web内容的最佳方式(Best way to display web content for specific country using mysql)

需要你的帮助。 我需要你们所有善良人士的建议。

我有一些内容,我只需要显示给几个国家。我可以通过Geoip.i将我的内容存储在MySQL数据库中,并使用country_code field.country代码可以为空或任何单个代码或组逗号分隔值

我想做的是,

  1. 检查country_code,如果为空,则显示所有用户的内容。
  2. 如果country_code不为空并且只有一个值,则仅显示给定country_code用户的内容。
  3. 如果country_code是逗号分隔值组,则显示所有逗号分隔的国家/地区用户的内容。

我有两种方法可以做到这一点

  1. 分别为each国家/地区添加数据列并显示内容,例如美国,英国,澳大利亚三个国家/地区的three columns ,如果用户的位置为美国,

    $sql=mysql_fetch_array(mysql_query("SELECT * FROM content_table WHERE US=='$country_code'")) ;

  2. 将单列的国家/地区数据添加为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,

  1. checking country_code and if it is empty, display that content for all users.
  2. if country_code is not empty and only a single value,display content only for the given country_code users.
  3. 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

  1. adding data columns for each country separately and display contents as for example three 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'"));

  2. 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

2023-02-05 19:02

满意答案

$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 the country_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?)

尝试使用重定向的网址。 您可以创建其他(非内容)页面(www.mypage.com/en-il/)并在标题中添加重定向: <html> <head> .... <script> // this will load the corresponding page window.location.assign("http://www.mypage.com/en-uk/"); </script> </head> <body> <!-- empty --> </body> </html> 这是第二个示例,...

不同的内容取决于具有相同URL的国家/地区(Different content depending on the country with the same URL)

来自Google Webmaster Central常见问题解答: Q: Can I use meta tags to specify geotargeting? A: Google does not use meta tags when determining geotargeting. https://sites.google.com/site/webmasterhelpforum/en/faq-internationalisation 让Google选择此选项的选项是为每个国家/地区提供的...

如何制作国家特定网站(和内容)?(How to make Country - Specific Web Site (and contents)? [closed])

您需要用户IP地址和IP 2位置 API。 尝试使用完整解决方案的以下示例来检测用户的国家/地区。 尝试 $userip = $_SERVER["HTTP_CLIENT_IP"]; $ip_data = json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$userip)); echo $ip_data->geoplugin_countryCode; 产量 我们 You need user IP Addre...

Google地方信息只能从特定国家/地区自动完成和组件限制搜索?(Google Places how to autocomplete and componentRestrictions search only from a specific country?)

Google Maps API Web服务应该与GET方法一起使用,而不是POST方法。 应该使用POST的唯一Web服务是Geolocation API 。 你应该改变代码 var headers = { 'User-Agent': 'Super Agent/0.0.1', 'Content-Type': 'application/x-www-form-urlencoded' }; // Configure the request var options = { ...

自动填充仅显示特定国家/地区或邮政编码的结果(autocomplete display only results from specific country or zip code)

您有几种类型的过滤器: 视口偏向 区域偏向 如果您更喜欢视口偏移,则应指定一个位置(您希望检索其周围信息的纬度/经度)和半径(返回“放置结果”的距离(以米为单位))。 如果您更喜欢Region Biasing,那么您必须提供一个区域(国家/地区代码,请参阅http://en.wikipedia.org/wiki/CcTLD )。 使用区域偏差的示例:maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types=geoco...

Bluehost MySQL国家/地区特定字符编码(Bluehost MySQL Country Specific Characters Encoding)

使应用程序在连接时将数据库连接的字符编码设置为UTF-8。 如何执行此操作取决于您用于访问数据库的API。 例如,在PDO中,您将charset=utf8添加到连接字符串。 After several hours of Googling, I found the solution. I only need to add the following line after my connection string. I use mysqli... $con = mysqli_connect("loca...

显示Web内容标题而不是“Web内容显示”(Display Web Content Title instead of “Web Content Display”)

我能想到的一个想法是通过portlet的Look and Feel隐藏标题“Web内容显示”,然后使用Structures & Templates创建Web内容。 在Template您可以指定要在Web内容顶部显示的title ,您可以使用一些css-magic将其定位到用于显示的portlet-title位置。 我想这应该不难。 <!-- position this div with the help of CSS to give the feel of the title --> <div c...

跨会话的用户特定内容建议[MySQL / Web](user-specific content suggestions across sessions [MySQL/Web])

CREATE TABLE interests (user_id int, tag varchar(25), weight int); 这样的事情。 每个用户每个标签一行。 当用户使用该标签读取/评论某些内容时,请加权。 CREATE TABLE interests (user_id int, tag varchar(25), weight int); Something like that. One row per tag for each user. Add to weight when a...

使用mysql显示特定国家/地区的Web内容的最佳方式(Best way to display web content for specific country using mysql)

$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=m...

相关文章

更多

Shiro整合到Web应用

添加了一个新的src/main/webapp/login.jsp文件和一个简单的登录表单以使用它来登录 ...

《Web开发的平民英雄:PHP+MySQL》扫描版[PDF]

中文名: Web开发的平民英雄:PHP+MySQL 作者: 丁月光 图书分类: 软件 ...

Web scraper open source

ByadminOnSeptember 10, 2012&middot;Add Comment ...

Solr与Mysql集成指南

Solr与Mysql集成指南 chuanliang于 2011-9-24,20:28 Comm ...

JAVA WEB

我也搞了几年JAVA了,由于一向懒惰,没有成为大牛,只是一普通程序猿,不爱玩社交网站,不爱玩微博,唯独 ...

web storm使用和配置

官网:http://www.jetbrains.com/webstorm/ webStorm,File ...

Solr与Mysql集成指南

在《企业级搜索引擎Solr使用入门指南》及《企业级搜索引擎Solr交流》中对Solr的使用做了简单介绍 ...

关于 style="display:none" 得问题

display:none 可以隐藏 该div. 要显示的时候,用block 或者 inline. ...

mysql问题

利用PreparedStatement执行插入,更新的操作时候: 如: PreparedState ...

MySql 查询语句中包含中文时不能查询结果 编码问题!

最近在做mysql查询时,发现一个很郁闷的问题:sql水土不服! 在公司内部做的mysql 查询,包 ...

最新问答

更多

Python / IPython奇怪的不可重现列表索引超出范围错误(Python/IPython strange non reproducible list index out of range error)

你得到IndexError的原因是你的输入文件显然不是完全用制表符分隔的。 这就是为什么当您尝试访问它时, splits[1]没有任何内容。 您的代码可以使用一些重构。 首先,你正在重复使用if -checks,这是不必要的。 这只是将cds0到7个字符,这可能不是你想要的。 我将以下内容放在一起,以演示如何重构您的代码,使其变得更加pythonic和干燥。 我无法保证它能够与您的数据集一起使用,但我希望它可以帮助您了解如何以不同的方式执行操作。 to_sort = [] # W

故事板从表格单元中延伸出来并显示其详细信息披露按钮(storyboard segue from a tablecell an its Detail Disclosure Button)

我不认为你可以链接一个特定的细节披露按钮瓦特/赛格。 我的故事板是非常程序化的B / C我使用了很多定制CGRect等。 所以我倾向于使用这样的东西: -(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"ViewControllerIdentifer"

我们可以将Gherkin功能文件与testcomplete集成(Can we integrate Gherkin feature files with testcomplete)

TestComplete不支持Gherkin功能文件。 但是,TestComplete具有SDK,因此可以自己为此创建扩展。 TestComplete does not support Gherkin feature files. However, TestComplete has SDK so it is possible to create an extension for this by yourself.

TrustAllCertificatesCallback被忽略(TrustAllCertificatesCallback is ignored)

我没有做过这样的事情,但看看我认为可以看出错误的例子。 试试这个代码: static class Program { static void Main() { var tcpclient = new TcpClient("remote.example.com", 443); var tcpstream = tcpclient.GetStream(); var sslstream = new SslStream(tcpstream,

返回嵌套元素的索引(Return index of nested element)

您需要获取父li元素的索引。 否则,您将获得列表项内锚点的索引,该索引始终为零。 $(this.parentNode).index(); You need to get the index of the parent li element. Otherwise you are getting the index of the anchor inside the list item, which will always be zero. $(this.parentNode).index();

在数组中重新编号元素的有效方法(Efficient way of re-numbering elements in an array)

您需要多次迭代列表,我认为没有办法解决这个问题。 毕竟,在开始更改元素(第二遍)之前,首先必须确定不同元素的数量(第一遍)。 但是请注意,由于对index的重复调用而not in列表中具有O(n),因此可能具有最多O(n ^ 2)的不同元素的数量。 或者,您可以使用dict而不是value_map的list 。 字典比列表具有更快的查找速度,因此,复杂性应该确实在O(n)的数量级上。 您可以使用(1)字典理解来确定旧值到新值的映射,以及(2)用于创建更新子项的列表理解。 value_map =

Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)

选项1 你可以改变这一行: app.use( express.static(__dirname + '/puplic')); //my public folder. 至 app.use('/oneTime', express.static(__dirname + '/puplic')); //my public folder 选项2 我假设你在公共文件夹中有一个js文件夹,然后你需要更改你的HTML代码:

使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)

对于计时器值,请在服务器端本身每秒更新本地计时器。 每当有任何用户进来时,给他这个值以及计时器的总值。 然后客户端将根据dandavis评论在本地启动自己的计时器,但在服务器端保留一些间隔,如15或10秒,服务器将广播当前计时器值,以便客户端相应地进行同步。 简而言之,服务器将每隔10(n:你决定)秒后广播,但它将在本地每秒更新定时器变量。 每当客户端进入时,它将获得总计时器值和当前计时器值。 广播当前出价的休息功能可以以正常方式完成。 For timer value, keep updatin

如何让XMLSerializer将命名空间添加到嵌套对象中的属性?(How do I get the XMLSerializer to add namespaces to attributes in nested objects?)

IXmlSerializable也许? 注意我还添加了(对A ): [XmlElement("A", Namespace = "http://www.example.com/namespace")] public TestSoapHeaderTypeValuePair A {...} 代码如下: public class TestSoapHeaderTypeValuePair : IXmlSerializable { private string _type; private