Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
object(stdClass)#2834 (2) { ["code"]=> string(3) "000" ["content"]=> object(stdClass)#2833 (4) { ["Customer_Name"]=> string(10) "Mr DsTEST" ["Status"]=> string(4) "Open" ["Customer_ID"]=> string(10) "1212121212" ["DUE_DATE"]=> string(19) "2019-07-23T00:00:00" } }

Please How do I loop through the above array from an external API in WordPress? I want to get the customer name, Status, Customer ID, and Due date and I also Want to show them in a table format.
whenever I use the below code The Strings will show nicely in a table, but I still get this error.
"Warning: Attempt to read property "Customer_Name" on string in C:\xampp\htdocs\wordpress\wp-content\plugins\product-open-pricing-name-your-price-for-woocommerce\product-open-pricing-for-woocommerce.php on line 402

Warning: Attempt to read property "Customer_ID" on string in C:\xampp\htdocs\wordpress\wp-content\plugins\product-open-pricing-name-your-price-for-woocommerce\product-open-pricing-for-woocommerce.php on line 403

Warning: Attempt to read property "Status" on string in C:\xampp\htdocs\wordpress\wp-content\plugins\product-open-pricing-name-your-price-for-woocommerce\product-open-pricing-for-woocommerce.php on line 404

Warning: Attempt to read property "DUE_DATE" on string in C:\xampp\htdocs\wordpress\wp-content\plugins\product-open-pricing-name-your-price-for-woocommerce\product-open-pricing-for-woocommerce.php on line 405"


What I have tried:

I have tried this
PHP
  1  	 echo '';
  2  
  3  	 echo '<table>';
  4  	 echo'<tr>';
  5  	 echo '<td> Customer Name</td>';
  6  	 echo'<td>Smart card No. </td>';
  7  	 echo '<td>Status</td>';
  8  	 echo '<td>Due Date</td>';
  9  	 echo '</tr>';
 10  	
 11  
 12  	
 13  foreach($thisresponse as $television) {
 14  
 15  
 16  	 echo'<tr>';
 17  	 echo '<td>' . $television->Customer_Name . '</td>';
 18  	 echo'<td>' . $television->Customer_ID . '</td>';
 19  	 echo'<td>' . $television->Status . '</td>';
 20  	 echo '<td>' . $television->DUE_DATE . '</td>';
 21  	 echo '</tr>';
 22  	}
 23  
 24  	echo '</table>';
Posted
Updated 9-Aug-21 21:30pm
v2

1 solution

Nobody can help you because we cannot see where your $thisresponse variable comes from.

However, the error message suggests that it's an array of strings. The string type does not contain properties called Customer_Name, Customer_ID, etc.

PHP: Strings - Manual[^]

You need to debug your code to work out why the array doesn't contain what you think it contains. We cannot do that for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900