php - how to echo an array of varriable in a page? -
i starting learning codes , writing codes echo array , give me error "warning: invalid argument supplied foreach() in c:\xampp\htdocs\ogmt\rest_server_api.php on line 62" how can solve this? code:
if($result1){ // script business no, amount & merchant id,output merchant page $query="select * customer_order insert_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"); } } foreach( $data $value ){ echo $value; } } else{ echo "wrong"; } }
you can use print_r() print array. this:
echo '<pre>'; print_r($data); echo '</pre>'; if $data array. can debug yourself.
note first declare $data array @ top of script. like: $data = array();
Comments
Post a Comment