如果1.1.2.254在我的数据库中存在!!使用下一个1.1.2.253问题



我有一个客户,我想给这些客户添加IP地址我使用loop $ I =254来自动添加IP地址但是它给所有的客户1.1.2.254我怎么能修复它

如果1.1.2.254存在于客户1,我需要做循环!!为客户2使用下一个1.1.2.253

$i=254
$res = MySQL_query("INSERT INTO `rm_users`(`username`, `staticipcpe`) VALUES ('$username', '1.1.2.$i');
$i--

使用IP unique in db插入,如果IP已退出

现在使用for($i=254;$i > 0;$i--){ $res = mysql_query("INSERT INTO `rm_users`(`username`, `staticipcpe`) VALUES ('$username', '1.1.2.$i')"); }

运行良好

这个问题有点不完整和不正确,但我认为您从输入或其他地方获得了IP地址。您可以通过查询来搜索此地址。

SELECT EXISTS(SELECT * FROM table1 WHERE ...)

this将返回一个true或false值。您可以浏览详细文档和类似问题

  1. 测试MySQL表中是否存在一行的最佳方法
  2. https://dev.mysql.com/doc/refman/8.0/en/exists-and-not-exists-subqueries.html
for($i=254;$i > 0;$i--){
$res = mysql_query("INSERT INTO `rm_users`(`username`, `staticipcpe`) VALUES ('$username', '1.1.2.$i')");
}

这将做的伎俩!这个循环将插入到1.1.2.1

最新更新