Jump to content

Archived

This topic is now archived and is closed to further replies.

mojito

sql question

Recommended Posts

I would like to understand the syntax used here as i want to access after the field in the table called thumbname

[code]select a.aid as AlbumID, a.Title as Title, a.pid as PictureID, p.thumbname as Picture, count(l.pid) as Cnt from albums a, pictures p, pictures l where a.aid = p.aid and a.pid = p.pid and a.aid = l.aid group by a.aid order by a.aid[/code]

what is the "as" bit doing?
im trying to loop through thus...
while($album = mysql_fetch_array($mysql)) {
echo $album[thumbname];

thanks

[img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]

Share this post


Link to post
Share on other sites
The "AS" part creates an alias.

So when you echo a field, you want to use the alias name instead of the actual field name (the part after the "as").

echo $album['Picture'];

Share this post


Link to post
Share on other sites
Thanks ober, thats really useful, but

I can see that "a" is later said to be album and "p" is said to be pictures but the bit I also dont get is the "l" or "1" here..

[code]pictures l where a.aid = p.aid and a.pid = p.pid and a.aid = l.aid group by a.aid[/code]

thanks for sharing your knowledge with us. [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.