Jump to content

Archived

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

homchz

Why does this not work??

Recommended Posts

[code]
class navigation
{
    var $u_links = array(
                    'Home'    => 'http://www.domain.com',
                    'Profile' => '?page=profile&uid=$u_id',
                    'Search'  => '?page=search');

    function navigation()
    {
         
    }
    
    function get_nav($u_id)
    {        
        foreach($this->u_links as $title => $url)
        {
            print "<a href=\"$url\">$title</a><br/>";
        }
    }
}

[/code]

The profile links does not recognize $u_id it only prints the literal $u_id.

Is this not possible??

Share this post


Link to post
Share on other sites

'Profile' => '?page=profile&uid=$u_id',


is there a ? missing only guessing.

Share this post


Link to post
Share on other sites
nope the format is correct. I just thought it would pick up the variable.

Share this post


Link to post
Share on other sites
Change [code]<?php 'Profile' => '?page=profile&uid=$u_id' ?>[/code] to [code]<?php 'Profile' => "?page=profile&uid=$u_id" ?>[/code]
Variables inside single quotes are not evaluated, those contained within double quotes are expanded.

Ken

Share this post


Link to post
Share on other sites
Tried that too but if I use double quotes in the array I get an"

Unexpected '"' error on that line.

Share this post


Link to post
Share on other sites
This should work:
[code]<?php
    var $u_links = array(
                    'Home'    => 'http://www.domain.com',
                    'Profile' => "?page=profile&uid=$u_id",
                    'Search'  => '?page=search');
?>[/code]
or
[code]<?php
    var $u_links = array(
                    'Home'    => 'http://www.domain.com',
                    'Profile' => '?page=profile&uid=' . $u_id,
                    'Search'  => '?page=search');
?>[/code]

Ken

Share this post


Link to post
Share on other sites
I'll advise you that it's probably not going to work as expected.

The variable in the array will be extended but it will have an empty value.

Share this post


Link to post
Share on other sites
[!--quoteo(post=380466:date=Jun 5 2006, 11:02 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 5 2006, 11:02 PM) [snapback]380466[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I'll advise you that it's probably not going to work as expected.

The variable in the array will be extended but it will have an empty value.
[/quote]

Yes I tried both methods before posting here and actually recieved errors. I got around this by passing a session variable and not URL variable.

Thanks for the advice though,

Josh

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.