获取名称列表(如果相同) [英] get list of names if its same
本文介绍了获取名称列表(如果相同)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获取具有注册了配置文件的IP地址的用户的昵称. 现在我知道我需要做一个if语句,好像ip_adres count()> 1反映IP地址,但是我如何使IP计数相等.
I want to get nicknames of users with same IP adres that has registred a profile. Now i understand that i need to make a if statement as if ip_adres count() > 1 echo the IP adres but how do i make the count of IP that equals.
<?php
$sql = "SELECT ip_adres, nickname2 FROM users";
$alias = $db->prepare($sql);
$alias->execute();
foreach($alias as $a){
$ip_adres = $a['ip_adres'];
$nickname = $a['nickname2'];
if($ip_adres){
echo "<pre>$nickname has a alias profile! $ip_adres</pre> ";
}
}
?>
输出
First has a alias profile! 213.93.99.38
Second has a alias profile! 213.93.99.38
Third has a alias profile! 213.93.45.33
Bla has a alias profile! 213.93.45.33
ZZZZ has a alias profile! 213.93
推荐答案
$sql = "SELECT ip_adres, nickname2 FROM users";
$users = $db->prepare($sql);
$users->execute();
$ips = array();
$aliases = array();
foreach($users as $user) {
if (in_array($user['ip_adres'], $ips))
$aliases[] = $user['ip_adres'];
$ips[] = $user['ip_adres'];
}
if (empty($aliases)) {
echo "Aliases not found";
}
else {
foreach($users as $user) {
if (in_array($user['ip_adres'], $aliases)) {
echo $user['nickname2'] . ' has a alias profile! '. $user['ip_adres'] .'<br/>';
}
}
}
这篇关于获取名称列表(如果相同)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文