php - Select one value from same column with same id -


i want select product detail , display 1 image of product same column.

ex :

fm_product table

| p_id | p_name | p_price | p_member_id | << (added product member) ----------------------------------------- | 1    | shirt  | 600     | 44          | | 2    | pants  | 700     | 44          | | 3    | shoes  | 800     | 45          | | 4    | bag    | 900     | 45          | 

fm_product_image table

| img_id | p_id_img | img_name    | ----------------------------------- | 1      | 1        | shirt_1.jpg | | 2      | 1        | shirt_2.jpg | | 3      | 1        | shirt_3.jpg | | 4      | 2        | pants_1.jpg | | 5      | 2        | pants_2.jpg | | 6      | 2        | pants_3.jpg | | 7      | 3        | shoes_1.jpg | | 8      | 3        | shoes_2.jpg | | 9      | 4        | bag_1.jpg   | | 10     | 4        | bag_2.jpg   | 

member ids 44 select added product out put should :

| p_name | p_price | img_name    | ---------------------------------- | shirt  | 600     | shirt_1.jpg | | pants  | 700     | pants_1.jpg | 

member ids 45 select added product out put should :

| p_name | p_price | img_name    | ---------------------------------- | shoes  | 800     | shoes_1.jpg | | bag    | 900     | bag_1.jpg   | 

my code

$result= mysql_query("select * fm_product left join fm_product_image on fm_product_image.p_id_img = fm_product.p_id p_member_id = '$id' " ) or die (mysql_error()); while ($row= mysql_fetch_array ($result) ){     $id=$row['p_id'];     <tr>     <td style="text-align:center; margin-top:10px; word-break:break-all; width:450px; line-height:100px;">     <?php if($row['p_id'] != ""): ?>        <img src="<?php echo $row['img_name']; ?>" width="100px" height="100px" style="border:1px solid #333333;">     <?php else: ?>        <img src="images/default.png" width="100px" height="100px" style="border:1px solid #333333;">     <?php endif; ?>     </td>     <td style="text-align:center; word-break:break-all; width:300px;"> <?php echo $row ['p_name']; ?></td>     <td style="text-align:center; word-break:break-all; width:200px;"> <?php echo $row ['p_price']; ?></td>     </tr>  } 

problem solved. thank guys much, i've tried code , it's worked.

select fm_product.p_name, fm_product_image.img_id, fm_product.p_price, fm_product.p_id, fm_product_image.img_1,group_concat(p_id_img) fm_product left join fm_product_image on fm_product_image.p_id_img = fm_product.p_id p_member_id = '8' group p_id 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -