(谷歌网站优化器的一种)PHP 中的随机化(但智能、快速且精简)
每次有人访问我的网站时,我都会显示三个选项之一(A、B、C)。如果用户喜欢该选项,他就会点击它。我想找到一种方法来显示点击次数较少的选项。在 PHP 中执行此操作的最佳方法是什么?
我通过简单地在数组中添加“投票”来保存 MongoDB 中的点击:
$option[]='a';//one click on option A
$option[]='b';//one click on option B
$option[]='b';//another click on option B
try{
$m=new Mongo();
$c=$m->db->clicks;
$c->save($option);
$m->close();
}
catch(MongoConnectionException $e){ die('Error connecting to MongoDB server. ');}
catch(MongoException $e){ die('Error: '.$e->getMessage());}
这将打印:
Array
(
[0] => a
[1] => b
[2] => b
)
Every time someone visits my site, I show one of three options (A, B, C). If the user likes the option, he clicks on it. I want to find a way to show the options that receive less clicks less frequently. What's the best way of doing this in PHP?
I am saving the clicks in MongoDB by simply adding a "vote" in an array:
$option[]='a';//one click on option A
$option[]='b';//one click on option B
$option[]='b';//another click on option B
try{
$m=new Mongo();
$c=$m->db->clicks;
$c->save($option);
$m->close();
}
catch(MongoConnectionException $e){ die('Error connecting to MongoDB server. ');}
catch(MongoException $e){ die('Error: '.$e->getMessage());}
This prints:
Array
(
[0] => a
[1] => b
[2] => b
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定我是否正确理解你的问题。但如果我这样做了,那么以下可能是一种相当幼稚,甚至可能是冗长的方式来做我认为你想做的事情:
Not sure if I understand your question correctly. But if I did, then the following is perhaps a rather naive, and perhaps even verbose way of doing what I think you want to do:
您可以使用 PHP 和数据库来完成此操作,但您可能更喜欢使用 Google Website Optimizer,我认为它提供了这个选项效果很好。
You CAN do it with PHP and a db, but you might prefer using Google Website Optimizer, I think it offers that option and works quite well.