0

I have two table as below

persons:

ID , FNAME, LNAME ,GENDER

100 , A , B , M

images:

IMG_D,IMG_NM,ID_PERSONS

10 , 1.JPG  , 100
20 , 2.JPG  , 100
30 , 3.JPG  , 100

the question is: I WANT QUERY RETRIEVE ALL COLUMNS FROM table persons and only IMG_NM FROM table IMAGES WITHOUT REST OF COLUMNS IN TABLE IMAGES

I MAKE QUERY AS BELOW

SELECT ID,FNAME,LNAME,GENDER,IMG_NM FROM persons,images where ID= ID_PERSONS  GROUP BY ID

the result:

100 , A , B , M , 1.JPG

AND I WANT SHOW ALL IMAGES WITHOUT REPEATING REST OF COLUMNS LIKE THAT

ID , FNAME, LNAME ,GENDER,IMG_NM

100 , A , B , M ,1.JPG
                ,2.JPG
                ,3.JPG 
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Handle custom display related things in application code. Dont complicate this at MySQL end; let it return a tabular data only. Remove `GROUP BY ID` from your sql. and then modify the result set in php – Madhur Bhaiya Sep 29 '18 at 20:19

1 Answers1

0

SELECT p.ID, p.FNAME, p.LNAME, p.GENDER, GROUP_CONCAT(i.IMG_NM) AS IMG_NM FROM persons p JOIN images i ON i.ID_PERSONS = p.id GROUP BY p.id;

Should handle what you're wanting nicely.

trollboy
  • 133
  • 7
  • thank you sir for response>>>it gives Warning: mysqli_query() expects parameter 2 to be string, object given in C:\xampp\htdocs\tesst\data.php on line 18 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\tesst\data.php on line 31>>can you help me with this error......I appreciate your effort ...thanks again – Bashar Hamdan Sep 29 '18 at 22:21
  • right, there's a bug in your php code that you've not posted. Basically you're doing the mysqli_query() wrong, and then since it's not running correctly you're doing a fetch_array against nothing which is the other error. – trollboy Sep 29 '18 at 22:24
  • that's correct i found the problem and its display only one blank image and didnt display the rest of images.... – Bashar Hamdan Sep 29 '18 at 22:46