954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Function Problem. Please help

This one isnt working!

function insertpath($num){
echo "          <td colspan=\"3\" align=\"left\"> \n";
echo "              <b>Date Published</b>:",$Date_Added[$num] ,"\n";
echo "              <b>Sample</b>:",$Sample_Views[$num],"</td>\n";
}
insertpath(0);


But this one Works

echo "          <td colspan=\"3\" align=\"left\"> \n";
echo "              <b>Date Published</b>:",$Date_Added[$num] ,"\n";
echo "              <b>Sample</b>:",$Sample_Views[$num],"</td>\n";


Well not woking in the sense the values of variables ($Date_Added[$num],$Sample_Views[$num]) not coming in the first. Whil in second its working!


Help me :(

bennetjosem
Newbie Poster
9 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

There are two things you need to do to troubleshoot this problem. INSIDE your function, at the very top, do this:

First, echo out one of the arrays like this:
[PHP]
echo "";
print_r($Date_Added);
echo "";
[/PHP]

Then echo out the value of $num:
[PHP]
echo "".$num;
[/PHP]

You should see that $num = 0, but that your array does not even exist. You forgot one important line at the top of your function:
[PHP]
global $Date_Added, $Sample_Views;
[/PHP]

Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 

Maybe concat syntax error :o

THIS....
echo "Sample:",$Sample_Views[$num],"\n";

SHOULD BE THIS....
echo "Sample:".$Sample_Views[$num]."\n";

senexom
Junior Poster in Training
54 posts since Jun 2005
Reputation Points: 11
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You