Jump to content

[SOLVED] passing params


zang8027

Recommended Posts

I got a php file called nav.php with the following code:

 

<?php

function navigation($home, $resume, $port, $contact)
{
	echo '

	<ul>
		<li><a href="index/"><img src="images/$home.png" alt="Home Page" /></a></li>
		<li><a href="resume/"><img src="images/$resume.png" alt="Resume" /></a></li>
		<li><a href="portfolio/"><img src="images/$port.png" alt="Portfolio Pieces" /></a></li>
		<li><a href="contact/"><img src="images/$contact.png" alt="Contact" /></a></li>
	</ul>
	';

}

?>

 

 

Then, in my main file, i am using require_once 'nav.php';.

 

Then, i am calling the function navigation("homeBtn", "resumeBtn", "portBtn", "contactBtn);

 

I am getting $contact.png etc.. instead of contactBtn so it acts like its not accepting my params.

 

Any idea?

Link to comment
Share on other sites

You need to use double quotes instead of single quotes for it to show the value of the variable. Or you could just do,

' . $home . '

etc.

 

So,

<?php

   function navigation($home, $resume, $port, $contact)
   {
      echo '

      <ul>
         <li><a href="index/"><img src="images/' . $home . '.png" alt="Home Page" /></a></li>
         <li><a href="resume/"><img src="images/' . $resume . '.png" alt="Resume" /></a></li>
         <li><a href="portfolio/"><img src="images/' . $port . '.png" alt="Portfolio Pieces" /></a></li>
         <li><a href="contact/"><img src="images/' . $contact . '.png" alt="Contact" /></a></li>
      </ul>
      ';

   }

?>

is one way.

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.