开发者

Array values written to SQL Server

My code shown below will successfully return an array of values using print_r. How can I can get each value to be inserted into SQL Server "on its own row" in the same column? So far, I have only been able to get the first value in the array to be written to my table. The additional value(s) are not written. Thx, _ JT

$host = '209.49.180.234';
$hostname = gethostbyaddr( $host );
$rbl  = 'hostkarma.junkemailfilter.com';
$lookup = $hostname . '.' . $rbl;
$value = gethostbynamel($lookup);

    if ($lookup != $value){

       print_r($value);
    }

I am unclear where to insert the loop. Like this?:

$host = '209.49.180.234';
$hostname = gethostbyaddr( $host );
$rbl  = 'hostkarma.junkemailfilter.com';
$lookup = $hostname . '.' . $rbl;开发者_如何学C
$value = gethostbynamel($lookup);
   if ($lookup != $value)
    foreach($value as $val) {
         mssql_query("INSERT INTO $table5 (Whitelist_code) VALUES ('".$val."')");
     }

mssql_close($conn);

I got it to work. Thanks guys! _ JT


Try this

<?php
  foreach($value as $val) {
    mssql_query("INSERT INTO table (value) VALUES ('".$val."')");
  }
?>


use a foreach loop

foreach ($value as $a):
    //access your rows as $a
    //ex.- echo $a; put your sql stuff here instead
endforeach;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜