Jump to content

use keys from associative array in and update statement.


kk4iku

Recommended Posts

I am pulling values from a text file and putting them in an associative array and then filtering them to get what I need. I would then like to use those key values in my MSSQL update statement. But I am not sure how to convey that to my MSSQL statement. How would I do that?

 

<?php
$lines = [];
$fp    = fopen('sample.txt', 'r');
while (!feof($fp))
{
  $line = fgets($fp);
  $lines[substr($line, 69, 5)] = substr($line, 117, 2);
}
fclose($fp);
$order=array_filter($lines,function($AA){ 
return $AA=='AA';}
);

$sql_update="update salesorders set ompOrderApproval= -1 where order_id in $orders_array_key_place_holder"

$connect = odbc_connect("1234");
$update = odbc_exec($connect, $sql_update);
odbc_close($connect);  
?>

 

Link to comment
Share on other sites

I update my code to use the implode and I changed my sql statement to test and I get the correct results. thanks

 

 

$lines = [];
$fp    = fopen('sample.txt', 'r');
while (!feof($fp))
{
  $line = fgets($fp);
  $lines[substr($line, 69, 5)] = substr($line, 117, 2);
}
fclose($fp);
$order=array_filter($lines,function($AA){ 
return $AA=='AA';}
);
$key_string = implode(',', array_keys($order));
//print_r($key_string);


$sql_update="select ompsalesorderid from  .SalesOrders where  ompsalesorderid in ($key_string)";
$connect = odbc_connect("1234");
$result = odbc_exec($connect, $sql_update);
if(!$result){
exit("Error in SQL");
}
 while ($row = odbc_fetch_array($result))
{
   $orderid=$row['ompsalesorderid'];
   echo $orderid;
 }


odbc_close($connect);
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.