Jump to content

Why does this not work??


homchz

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??
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.