1 satır MySQL bilgi hizalama

0 Cevap php

Ben MySQL bu üç tablo.

Sanatçıların isimleri Tablo (m) Ürün iformations Tablo, bu durumda, resim adresleri (p) Sanatçılar ve Ürünleri id kimliği vardır Tablo. (Pmx)

I'm trying to Join them together so I get 1 row for each Artists. There are several images in p table for 1 Artists. I added a column called mf_prior where are the numbers of images (user assigns the numbers hiself and select those 3 images that he wants to be displayd on the front-end). I'm searching Artists (manufacturers) by Letters for ex. "M"

Fikir ben almak isterim ki

  1. manufacturer_id | mf_name | img1_id | img1_address | img2_id | img2_address | img3_id | img3_address

Ben alıyorum

  1. manufacturer_id1 | mf_name1 | img1_id | img1_address | NULL | NULL | NULL | NULL
  2. manufacturer_id1 | mf_name1 | NULL | NULL | img2_id | img2_address | NULL | NULL
  3. manufacturer_id1 | mf_name1 | NULL | MULL | NULL | NULL | img3_id | img3_address

Ben bu MySQL SEÇİMİ var:

SELECT
 m.manufacturer_id ,
 m.mf_name ,
 p1.product_id AS pimg1 ,
 p1.product_full_image AS p1 ,
 p2.product_id AS pimg2 ,
 p2.product_full_image AS p2 ,
 p3.product_id AS pimg3 ,
 p3.product_full_image AS p3 
FROM
 jos_vm_product_mf_xref AS pmx 
JOIN
 jos_vm_manufacturer AS m ON m.manufacturer_id = pmx.manufacturer_id 
JOIN
 jos_vm_product AS p1 ON p1.product_id = pmx.product_id AND p1.mf_prior = 1
JOIN
 jos_vm_product AS p2 ON p2.product_id = pmx.product_id AND p2.mf_prior = 2
JOIN
 jos_vm_product AS p3 ON p3.product_id = pmx.product_id AND p3.mf_prior = 3

WHERE
 m.mf_chars = 'm'

sonuç olarak ben 3 satır olsun ve yerlerde ben NULL olsun - yukarıda gösterildiği gibi

Daha iyi bir SEÇ yazmak ya da PHP ile sonucu ispatlamak için - Belki de kimse bu konuda bana yardımcı olabilir

0 Cevap