A
A
ART42018-11-21 16:26:06
MySQL
ART4, 2018-11-21 16:26:06

Binding the id (article) of the product to the contentid (image) how?

Good evening, I'm trying to make it so that from 1 table where there is an ID value, it is bound in another table where there is contentid.
Here is the table of the articles themselves. This table is where the article ID should be assigned
ba4a8a3efe.png
when adding
a6991cf625.png

SELECT modx_site_tmplvar_contentvalues.contentid FROM 
modx_site_tmplvar_contentvalues  
INNER JOIN 
modx_site_content
ON 
modx_site_content.id = modx_site_tmplvar_contentvalues.contentid
 ORDER BY `contentid` DESC

doesn’t want to, got confused in general, tell me how to add that record ID of the last modx_site_content table , and assigned the last added modx_site_tmplvar_contentvalues
​​record The id itself adds:
SELECT LAST_INSERT_ID();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Just A Bit, 2018-11-21
@ART4

If 1 article + 1 picture (you just need to select the desired "tmplvarid")

SELECT * FROM modx_site_content AS msc
LEFT JOIN modx_site_tmplvar_contentvalues AS mstc
ON msc.id = mstc.contentid AND mstc.tmplvarid = 1
ORDER BY mstc.contentid DESC

All pictures + All articles to them
SELECT * FROM modx_site_tmplvar_contentvalues AS mstc
LEFT JOIN modx_site_content AS msc
ON msc.id = mstc.contentid
ORDER BY mstc.contentid DESC

LEFT JOIN or INNER JOIN, you decide.
I hope I understood you correctly :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question