Jump to content


Photo

Why does this not work??


  • Please log in to reply
7 replies to this topic

#1 homchz

homchz
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts
  • LocationLee, New Hampshire

Posted 06 June 2006 - 12:48 AM

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/>";
        }
    }
}


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

Is this not possible??

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 06 June 2006 - 12:57 AM


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


is there a ? missing only guessing.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 homchz

homchz
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts
  • LocationLee, New Hampshire

Posted 06 June 2006 - 12:59 AM

nope the format is correct. I just thought it would pick up the variable.

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 06 June 2006 - 01:35 AM

Change
<?php 'Profile' => '?page=profile&uid=$u_id' ?>
to
<?php 'Profile' => "?page=profile&uid=$u_id" ?>
Variables inside single quotes are not evaluated, those contained within double quotes are expanded.

Ken

#5 homchz

homchz
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts
  • LocationLee, New Hampshire

Posted 06 June 2006 - 02:02 AM

Tried that too but if I use double quotes in the array I get an"

Unexpected '"' error on that line.



#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 06 June 2006 - 02:57 AM

This should work:
<?php
    var $u_links = array(
                    'Home'    => 'http://www.domain.com',
                    'Profile' => "?page=profile&uid=$u_id",
                    'Search'  => '?page=search');
?>
or
<?php
    var $u_links = array(
                    'Home'    => 'http://www.domain.com',
                    'Profile' => '?page=profile&uid=' . $u_id,
                    'Search'  => '?page=search');
?>

Ken


#7 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 06 June 2006 - 03:02 AM

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.
~ D Kuang

#8 homchz

homchz
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts
  • LocationLee, New Hampshire

Posted 06 June 2006 - 10:28 AM

[!--quoteo(post=380466:date=Jun 5 2006, 11:02 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 5 2006, 11:02 PM) View Post[/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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users