php - Join SQL query that has single id/row in 1 table, but links to multiple rows(same id) in another table? -
Sorry for the first long question title.
My question / status is like this.
1.) I have 2 tables in mysql
2.) In the first table, each list has a unique ID (each list is in 1 row)
< P> 3.) In the second table, its name / tag is for the ID listed from the first ID, the first table4. ) Each entry can have multiple images (multiple lines in the second table).
What I'm trying to do, is to drag all the lists from Table 1 and then use the pulling list.id one from the table, from Table 2, all the lines of pictures that are listing.id I am confused at this time because there are several rows, whose list contains the same list. Table 2 And I tried to display * * *, but it only resonates the last image (row) from table 2.
When I am in 2 tables, it does not seem to work. And I am not sure if I ask it twice, then press the array together.
Thank you for your time
$ result = mysqli_query ($ con, select "listing" from listingpic ON (listing.id = listingpic.listingid) Where date & gt; = curate () - interval defoff (credit) + 300 days group listing. ID order of living.id dessc ") or die (Mycamille_Apple ($ Conn)); While ($ line = mysqli_fetch_assoc ($ result)) {$ output [] = $ line; } If (! Empty ($ output)) {echo json_encode ($ output);} else {echo json_encode ([]); }
You receive only one result per ID, because you have GROUP BY used Listing.id
. If you do not group them, then you get a result row for each table 2 row, which contains the listing ID each time.
If you use the data in a query "Data ID: Multiple Data Recovery in Multiple," you can use for example, and then Explosion ()
Recover string result.
Otherwise, get all the IDs from Table 1 and then iterate over PHP and an additional ID per query
Comments
Post a Comment