Reply to Re: newbie: accessing columns in a select

Your name:

Reply:


Posted by Carl on 11/24/05 02:45

Jeff wrote:
> php version 5
>
> Here is some code from index.php:
> $sql = "select A.text, A.link, B.text, B.link, C.text, C.link from menu A,
> menu B left outer join menu C on B.MenuItemID = C.parent where B.parent =
> A.MenuItemID and A.MenuItemID = $MenuItem";
>
> $result = $dbh->query($sql);
> while ($menuitem = $result->fetch_assoc())
> {
> echo "<a href={$menuitem['Link']}>{$menuitem['text']}</a>";
> echo "<br>";
> }
>
> As you can see from my select, I've joined the menu table with itself 3
> times...My problem is in this line:
> echo "<a href={$menuitem['A.Link']}>{$menuitem['A.text']}</a>";
>
> I cannot access the columns in the resulset using A.Link, A.text, B.Link
> etc... But I want to access them, how do I access the columns here?
>
> Please, help me with this problem!
>
>
> Jeff
>
>

Try :

$sql = "select A.text as atext, A.link as alink, B.text as btext, B.link
as blink, C.text as ctext,"..., etc.

Then reference them by their assigned name (i.e alink/atext).

Carl.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация