I don’t know MySQL very well so I need a bit of help with this task.. I hope it’s ok to ask.
I have a table that i need to export which i did using the following code:
SELECT *
FROM `members`
WHERE `active` =1
AND `level` = 'full'
LIMIT 0 , 30000
This works perfect and gives me most of what I need including a user ID in the collumn called id but I also need to grab the related image for each member and add it to my exported .csv.
The images (filename) are stored in a different table called images but this only contains galleryid, filename and defaultimg (note I am only interested in data where defaultimg = 1)
The issue here is there is NO reference to the member (id) in this table.
For that I have to reference a different table called: imagelinks which contains 2 columns:
1) id which relates to my galleryid from the images table.
and
2) memberid which relates to the user ID id from the members table.
What a disaster of a setup I know.
So.. what I need to do and can’t for the life of me work out is export a .csv with ALL the user data from the members table (as stated in my code above) with the addition of the filename data from the images table that coresponds to the referenced user (where defaultimg = 1).
Lastly, I also need to prepend a URL to the front of the filename data.
eg: The table has my-image.jpg but in the exported .csv I need it to be http://www.domain.com/images/my-image.jpg
I’m trying to do all of this in PhpMyAdmin.
Any help with this will be very much appreciated.
Thanks
My syntax might be a bit off but this should be close…
SELECT members.*, CONCAT(‘http://www.domain.com/images/’, images.filename) AS thefilename FROM members INNER JOIN imagelinks ON members.id=imagelinks.memberid INNER JOIN images ON images.galleryid=imagelinks.id WHERE members.active=1 AND members.level=’full’ AND images.defaultimg=1