For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > November 2005 > newbie: accessing columns in a select









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author newbie: accessing columns in a select
Jeff

2005-11-23, 6:56 pm

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


Carl

2005-11-23, 6:56 pm

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

2005-11-23, 9:55 pm

thanks, it works now

"Carl" <_Nospam_@_DO_NOT_.USE> wrote in message
news:138hf.23882$dO2.10617@newssvr29.news.prodigy.net...
> Jeff wrote:
>
> 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.



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com