0

I tried to assigned the php string into my csv cell value, but cell always return blank value. The value it self came from 2 requests, one from mysql and another from curl. from mysql request it's working fine but when I assigned the value from curl request, I face this problem.

here my code so far:

    foreach ($arr->data as $datas) {
        foreach ($datas->location as $locations) {
            $item_id = json_encode($locations->item_id) . "\n";
            $area_id = json_encode($locations->area_id) . "\n";
            $staff_id= json_encode($locations->staff_id) . "\n";


while($row = $query->fetch_assoc()) {
###This row from mysql###
....
##started row from curl###
if($row['item_id'] == $item_id && $row['area_id'] == $area_id){
            $activeSheet->setCellValue('O'.$i , $staff_id);
        }
....

This part it's not working $activeSheet->setCellValue('O'.$i , $staff_id); but if I echo or print it, the value appeared.

Anyone can help :(, almost a week try to solved this

Bekka
  • 39
  • 6
  • `$staff_id= json_encode($locations->staff_id)` means you're converting it to an object. Before you can put it in the Cell you might need to convert it back? Or do you actually want to insert `json` in your excel cell? – Andrea Olivato Jun 27 '21 at 00:34
  • Hi @AndreaOlivato I tried both, ``$staff_id= json_encode($locations->staff_id)`` and ``$staff_id= $locations->staff_id``. but returned same result, seem like the value did not insert to the cell :( – Bekka Jun 27 '21 at 22:54
  • But also the checks you perform before `if($row['item_id'] == $item_id` , $item_id is a json_encode . Have you tried `echo $row['item_id']` and `echo $item_id` to see what they contain? – Andrea Olivato Jun 28 '21 at 02:32
  • Tried it before but retun `Parse error: syntax error, unexpected 'echo' (T_ECHO) ` :( I am curios, the suspect is cause by I call the json data inside of while get row? – Bekka Jun 28 '21 at 08:02

0 Answers0