homchz Posted June 6, 2006 Share Posted June 6, 2006 [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?? Quote Link to comment https://forums.phpfreaks.com/topic/11285-why-does-this-not-work/ Share on other sites More sharing options...
redarrow Posted June 6, 2006 Share Posted June 6, 2006 'Profile' => '?page=profile&uid=$u_id',is there a ? missing only guessing. Quote Link to comment https://forums.phpfreaks.com/topic/11285-why-does-this-not-work/#findComment-42247 Share on other sites More sharing options...
homchz Posted June 6, 2006 Author Share Posted June 6, 2006 nope the format is correct. I just thought it would pick up the variable. Quote Link to comment https://forums.phpfreaks.com/topic/11285-why-does-this-not-work/#findComment-42248 Share on other sites More sharing options...
kenrbnsn Posted June 6, 2006 Share Posted June 6, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/11285-why-does-this-not-work/#findComment-42253 Share on other sites More sharing options...
homchz Posted June 6, 2006 Author Share Posted June 6, 2006 Tried that too but if I use double quotes in the array I get an"Unexpected '"' error on that line. Quote Link to comment https://forums.phpfreaks.com/topic/11285-why-does-this-not-work/#findComment-42259 Share on other sites More sharing options...
kenrbnsn Posted June 6, 2006 Share Posted June 6, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/11285-why-does-this-not-work/#findComment-42276 Share on other sites More sharing options...
poirot Posted June 6, 2006 Share Posted June 6, 2006 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 Link to comment https://forums.phpfreaks.com/topic/11285-why-does-this-not-work/#findComment-42279 Share on other sites More sharing options...
homchz Posted June 6, 2006 Author Share Posted June 6, 2006 [!--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 Quote Link to comment https://forums.phpfreaks.com/topic/11285-why-does-this-not-work/#findComment-42356 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.