I am trying to populate a dropdown from the ZOHO API response I am getting with my request. I have two files. request.php and zoho.php.
I am receiving the response from request.php as below.
object(stdClass)#2 (4) { ["code"]=> int(0) ["message"]=> string(7) "success" ["invoices"]=> array(200) { [0]=> object(stdClass)#3 (54) { ["invoice_id"]=> string(19) "2163791000003899301" } } }
in order to get the result I am decoding the object as below
$result = curl_exec($ch); curl_close($ch); $decode_data = json_decode($result); var_dump($decode_data);
I am having a popup in zoho.php.
<select value="Select Zoho Invoice" name="zohoinvoice" id="zohoinvoice" class="SlectBox form-control"> <?php echo zohoFunc(); ?> </select> function zohoFunc(){ global $decode_data; $output=''; $output .= '<option value = "Select Invoice">Select Invoice</option>'; foreach($decode_data as $inv){ $output[] .= '<option value = "'.$inv[0]->invoice_id.'">'.$inv[0]->invoice_number.'</option>'; } return $output; }
The way I am looping the data I have received is below. I am trying to get as the way how we populate a dropdown from SQL which is a string and zoho’s case its an array. Where I am making the mistake?
Advertisement
Answer
The above answer gave me an idea to loop through the result on zoho.php itself and get the value to dropdown HTML.
function zohoFunc(){ global $decode_data; global $result; $output=''; $output.= '<option value = "Select Invoice">Select Invoice</option>'; foreach($decode_data['invoices'] as $result) { $invoice_number = $result['invoice_number']; $_invoiceReturn .= '<option value = "'.$invoice_number.'">'.$invoice_number.'</option>'; } return $output; }