I’m running this function which is selecting data and I”m having it thrown into another function for inserting but upon errors and doing a var_dump of my results (which successfully dumped an array) I’m getting “illegal string offset” for each column”
Even though I’m casting these values, my array is basically printing each values as string(1) “number” or string(10) “value” so I know that I don’t have the column names as indexes here.
What am I doing wrong?
edit: error message PHP Warning: Illegal string offset 'QT' in line 38
public function ref() { $sql = "select cast(co as DECIMAL) as co, cast(sl as DECIMAL)as sl, cast(pr as character(10)) as pr, cast(qt as decimal) as qt FROM tableOne"; $results = odbc_exec($this->DB2Conn, $sql); $log=''; if ($results) { while($row = odbc_fetch_array($results)) { foreach($row as $r){ $res = $this->add($r['sl'], $r['pr'], $r['qt'], $r['co']); } } } return $log; }
Advertisement
Answer
Your inner foreach is not needed
if ($results) { while($r = odbc_fetch_array($results)) { $res = $this->add($r['sl'], $r['pr'], $r['qt'], $r['co']); } }