i have 2 tables
1st table called services has id_service, name, date. description
2nd table called services_images has id_img, img_name,id_service
Let’s say now that I have to, with one query (if possible), return 2 arrays
1st array with fields from one specific id from table "services"
2nd array with fields from all the images related to the selected id in “services” from table "services_images"
or better yet, only one array with the same data as said in 1, with an array INSIDE called “images” that has all the images listed from the table "services_images"
I need this to process and show data in a html page and this is the only way.
If I cant do it in mysql how can I arrange this in PHP, the only thing I can think of is 2 queries
Plus I’m always trying to improve my skills since I used to make single queries for everything, are there cases where making 1 query it’s just impossible?
Thanks!
For eaxmple with PDO:
Beware though.. if the two tables youre joining (in this case
servicesandservices_images) have any columns with the same name you will only get the value for the last one retrieved in the row unless you alias them or exclude them form your select statement.Additionally, if the size of your results is big you may have to use two queries similar to what Thomas has suggested because you may not have enough memory to hold the complete array structure.