php mysql循环插入IP地址块

时间:2013-12-24 07:32:52

标签: php mysql ip ip-address

如何基于/ 24块插入256个IP。如果IP块是192.168.1.0/24& network是192.168.1.0所以我想创建一个循环来将192.168.1.0插入到mysql表中的192.168.1.255。按下时会有一个按钮,它会插入256行0到255 ..请帮我在php mysql中执行此操作

if (isset ( $_POST ['doSubmit'] ) && $_POST ['doSubmit'] == 'Submit Details') {
  // Filter POST data for harmful code (sanitize)
  foreach ( $_POST as $key => $value ) {
    $data [$key] = filter ( $value );
  }
  $network = $data [network]; // Is network ip 192.168.1.0
  // Action will go here
}

1 个答案:

答案 0 :(得分:0)

  

所以我想创建一个循环,将192.168.1.0插入到192.168.1.255中   mysql表

像这样生成......

foreach(range(0,255) as $val)
{
    $arr[]="192.168.1.".$val;
    //Running a query 255 times here is not a good idea !
}

//$arr now holds all your IPs , you could push it into your SQL Query..