Here’s the scenario:
- I receive a JSON object comprising 140 events. Each event is one of six possible types and includes several details, except for 2 (description and contact name).
- I have a MySQL database of the 6 descriptions and contact names.
How can I “attach” the correct description and contact name from the database to each JSON entry in PHP?
I could do a query of the database for each of the events, but this seems needlessly complex and I imagine it would severely slow performance. The best option would be for the provider of the web service to include our descriptions and contact names, but they won’t do that.
Thanks in advance.
If you can identify which of the 6 descriptions/contact names you want for each event, then instead of getting them from the database for each event, select them all first then do the lookup in PHP.
For example:
I’ve made some assumptions here, but you should get the general idea. Note you need to do a
forloop not andforeachif you want to modify the$all_eventsarray as you go.