php - how to echo an associative array in a page? -
i starting learning codes , writing codes echo array , give me 2 errors:
warning: array_keys() expects parameter 1 array, null given in c:\xampp\htdocs\ogmt\rest_server_api.php on line 70
warning: invalid argument supplied foreach() in c:\xampp\htdocs\ogmt\rest_server_api.php on line 71..
how can solve this? code:
if($result1){ // script business no, amount & merchant id,output merchant page $query="select * customer_order order_time=(select max(order_time)from customer_order)"; $result=mysql_query($query); while($row=mysql_fetch_assoc($result)){ $amount=$row['amount']; $id=$row['merchant_id']; $payment_mode=$row['mobile_service']; switch($payment_mode){ case 'tigo-pesa': $result1=mysql_query("select * mobile_client mobile_service='tigo-pesa'"); while($row1=mysql_fetch_assoc($result1)){ $data=array( 'business no'=>$row1['business_no'], 'payment mode'=>$payment_mode, 'total amount tsh'=>$amount, 'merchant id'=>$id ); }break; case 'm-pesa': $result1=mysql_query("select * mobile_client mobile_service='m-pesa'"); while($row1=mysql_fetch_assoc($result1)){ $data=array( 'business no'=>$row1['business_no'], 'payment mode'=>$payment_mode, 'total amount tsh'=>$amount, 'merchant id'=>$id ); }break; case 'airtel-money': $result1=mysql_query("select * mobile_client mobile_service='airtel-money'"); while($row1=mysql_fetch_assoc($result1)){ $data=array( 'business no'=>$row1['business_no'], 'payment mode'=>$payment_mode, 'total amount tsh'=>$amount, 'merchant id'=>$id ); }break; // default: $data=array('error'=>"no payment mode selected"); } $response=array('details'=>$data); } } else{ $response=array('details'=>"query failed!"); } } //print output merchant page complete payment $keys = array_keys($data); foreach($response['details'] $keys=>$value){ echo "$keys: $value</br>"; } ?>
you can not echo array, can try either var_dump($data);
or print_r($data)
also can use implode("", $_post[$data]);
,that closer echo.
Comments
Post a Comment