Forum Moderators: coopster

Message Too Old, No Replies

Passing variable between functions on the same page

         

nshack31

3:58 pm on Mar 4, 2005 (gmt 0)

10+ Year Member



I have a function (below). The part I am confused abbout is the variable $cnt (in bold). I wish to use this variable in another function that is on the same PHP page, how can I pass the $cnt variable onto another function in the same page? I keep gettin the undefind variable message! Thanks


function getDateLink($day, $month, $year)
{
include 'open.php';

$query="Select * From challenge Where confirmed = 'Yes' AND month = '$month' AND year = '$year'";
$result = mysql_query($query);

$teamday='';
$teammonth='';
$teamyear='';
$link = '';
$cnt = 0;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$teamday[]=$row['day'];
$teammonth[]=$row['month'];
$teamyear[]=$row['year'];
[b]$cnt++;[/b]
if(in_array($day,$teamday) and in_array($month,$teammonth) and in_array($year,$teamyear))
{
$link = "displaymatches.php?day=$day&month=$month&year=$year";
}

}
return $link;
include 'close.php';

}

ergophobe

4:25 pm on Mar 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There's a thread in the forum library [webmasterworld.com] which is sort of a beginner's guide to functions and variable scope [webmasterworld.com].

I think that will help you get it sorted. See especially messages #2 and #7

[edited by: ergophobe at 6:52 pm (utc) on Mar. 4, 2005]

nshack31

6:39 pm on Mar 4, 2005 (gmt 0)

10+ Year Member



sorted, thanks