Jump to content

Passing Variable returns only first word?


jonnypixel

Recommended Posts

Hi, ( Thanks for any help in advance )

 

I am still learning php and if some one could help i would be very grateful, cheers.

 

I have a menu system and it displays on my tabs correctly but when i hover over the Names with Two words ( eg: Brown Bread )

 

It only shows

 

&cat=Brown  ( In my URL )

 


$link = 'index.php?area=mypage&cat=';

$html .= '<li><a href='.$link.''.$menuData['items'][$itemId]['name'].'>' .$menuData['items'][$itemId]['name']; 

   // find childitems recursively
            $html .= buildMenu($itemId, $menuData);

            $html .= '</a></li>';

 

Can any one please help as to how i can keep the full two words showing in my link please?

 

I want it to show

 

&cat=Brown Bread  ( In my URL )

 

I have tried variations of "\"  "\"  and  '\'    '\'  But it either shows me an error or just adds it to the link URL.

 

 

You should always use quotes on attribute values in HTML tags:

<a href="xyz.php?x=this is a test">x</a>

You can also use urlencode

<a href="http://www.example.com/test.php?x=<?php echo urlencode("this is a test");?>">y</a>

 

In you case, do something like:

<?php
$html = '';
$link = 'index.php?area=mypage&cat=';
$html .= '<li><a href="'.$link.''.$menuData['items'][$itemId]['name'].'">' .$menuData['items'][$itemId]['name']; 
   // find childitems recursively
$html .= buildMenu($itemId, $menuData);
$html .= '</a></li>';
?>

 

If you had looked at the generated code, you would have seen that the rest of your string was there.

 

Ken

Archived

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

×
×
  • 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.