Search code examples
phparraysodbc

Using odbc_fetch_array but got "arrayarrayarray "instead


I try to get value by using odbc_fetch_array and turn them into variable but when i try to echo it's just said "arrayarrayarray"

Array ( 
  [0] => Array ( [PKDSEQ] => 154604 ) 
  [1] => Array ( [PKDSEQ] => 154604 ) 
  [2] => Array ( [PKDSEQ] => 154529 ) 
  [3] => Array ( [PKDSEQ] => 161689 ) 
  [4] => Array ( [PKDSEQ] => 158940 ) 
  [5] => Array ( [PKDSEQ] => 155383 ) 
  [6] => Array ( [PKDSEQ] => 156247 ) 
  [7] => Array ( [PKDSEQ] => 158123 ) 
)

and is there a way to get array separate into number?

Code

  $PKDSEQ2 = array();
  $table4 = "SELECT [PKDSEQ] FROM [PWSWMS].[dbo].[tbTR_PACKD] WHERE [PKDSEQ] = '$PKDSEQRS5'";
  $RS4 = odbc_exec($connection2, $table4);

  while ($PKDSEQ2 = odbc_fetch_array($RS4)) {
    $PKDSEQ[] = $PKDSEQ2;
  }
}

print_r(array_values($PKDSEQ));

if(isset($_POST['QTYINPUT1'])) {
  $QTYINPUT1 = $_POST['QTYINPUT1'];
  $update = "UPDATE [PWSWMS].[dbo].[tbTR_PACKD] SET QTYPCK='$QTYINPUT1' WHERE [PKDSEQ]='$PKDSEQ[1]'";
  $result = odbc_exec($connection2, $update);
  echo "<br>$QTYINPUT1";
  echo "<br>$PKDSEQ[1]";
}

Solution

  • You've got an associative array within each entry in $PKDSEQ. So you need to refer to the property of that array which you want to output. Since the array happens to only have one property, it's pretty simple to choose:

    echo "<br>".$PKDSEQ[1]["PKDSEQ"];