Jump to content


Photo

sql question


  • Please log in to reply
2 replies to this topic

#1 mojito

mojito
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 22 May 2006 - 06:18 PM

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

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

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\" /]



#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 22 May 2006 - 07:05 PM

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'];

Info: PHP Manual


#3 mojito

mojito
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 22 May 2006 - 08:42 PM

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..

pictures l where a.aid = p.aid and a.pid = p.pid and a.aid = l.aid group by a.aid

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\" /]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users