EllisLab text mark
Advanced Search
     
SQL Query help - latest posts by author
Posted: 15 August 2011 01:18 PM   [ Ignore ]
Joined: 2007-06-07
286 posts

Hi,

Could really do with some SQL Query help/advice on this.


I’m trying to create a short sidebar list of latest posts from a channel, with each post by a separate author.
Could someone help as regards merging these queries I think I have (sort of) working separately?

format:

screen name
thumbnail
title


this query code creates a list, but with author_id rather than screen name
title works ok, but the thumbnail doesn’t load and the path doesn’t write properly.

{exp:query sql="SELECT t.title, t.author_id FROM exp_channel_titles t 
ORDER BY author_id ASC LIMIT 4"
}
{author_id}
<br />
<
a href="{path=portfolios/gallery/{username}}"><img src="{thumbnail}"></a><br>
<
a href="{path=portfolios/gallery/{username}}">{title}</a><br />
{/exp:query} 

This query code create the path properly and the user name properly but the title is just appearing as {title}
thumbnail doesn’t load.

{exp:query sql="SELECT m.member_id, m.username, m.screen_name, m.avatar_filename FROM exp_members m 
WHERE m.group_id='5' "
}
{screen_name}
<a href="{path=portfolios/gallery/{username}}"><img src="{thumbnail}"></a><br>
<
a href="{path=portfolios/gallery/{username}}">{title}</a><br />
{/exp:query} 

I presume I need to use a JOIN but I’m really not that expert with SQL queries.

thumbnail is a field in exp_channel_fields - any idea how I get this into the query?
the filename for the image is in exp_channel_data but it is like this -

{filedir_1}13.jpg 

how do I get rid of the

{filedir_1} 

bit or create a path?

or should I be using {exp:channel: in there as well ?

 
Posted: 15 August 2011 04:59 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2007-06-07
286 posts

No SQL Query experts on the forum at all?
Seems to be a real lack of examples or documentation for how to do stuff with SQL Queries here.

I’ve tried to get the image file list first which seems to be working

{exp:query sql="SELECT d.file_name, c.channel_name FROM exp_files d INNER JOIN exp_channels c
WHERE c.channel_name='portfolios' ORDER BY d.file_id ASC LIMIT 4"
}
{file_name}
{
/exp:query} 

is ORDER BY exp_files.file_id the right way to go to get a latest entry list?

How in an SQL query do you join more than 2 tables?
do you repeat the INNER JOIN or use a comma or something? INNER JOIN exp_channels, exp_channel_data etc.,?

 
Posted: 16 August 2011 11:17 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2007-06-07
286 posts

Any advice on what to do ?