需要在一个查询查询中从一个表中检索数据,条件“where”同时检查另一个表是否存在ip user,然后显示结果,同时显示信息是否存在ip
表:
Ips (
Id int (10) not null auto_increment,
User_id int (10) not null default '0',
Ip varchar (40) not null
)
Users (
Id int (11) not null auto_increment,
Username varchar (35) not null,
Email varchar (200) not null,
Salt varchar (40) not null,
Password varchar (40) not null,
Country varchar (40) not null
)
我想得到什么:
从users表中获取数据,条件为“where country ='paris'LIMIT 0.10”
每次检查ips表是否存在带有$ _SERVER的用户ID和IP地址['REMOTE_ADDR']
如果表格中有记录,则在
我目前的问题代码:
<?php
include "connect.php";
$db = mysqli_query($connect, "SELECT * FROM users JOIN ips ON ips.user_id=users.id ON ips.ip='".$_SERVER['REMOTE_ADDR']."' WHERE users.country='paris' LIMIT 0,10");
if (mysqli_num_rows($db)>0){
while ($data = mysqli_fetch_assoc($db)){
print_r($data);
if (filter_var($data['ip'], FILTER_VALIDATE_IP)){ //check var is ip adress
echo '<br>isset ip';
}
}
}else{
echo 'not records';
}
?>
Ps:我在提案中找不到答案
答案 0 :(得分:0)
尝试此查询:
SELECT * FROM Users WHERE Country ='paris' AND Id IN (SELECT User_id FROM Ips WHERE Ip = 'ip_adddress')