Jump to content


Photo

Display return value problem


  • Please log in to reply
1 reply to this topic

#1 crossline

crossline
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 March 2006 - 07:54 PM

Hi all,
I try to display result calculation data from text file using return(). But the problem is no display result on page. If I use echo in my function it will print the result. But I dont want to use echo in my function because i need to loop the result in html table.
Could anyone help me?

Thanks in advance,

Here is the code :

class test
{
   function count($n,$fp1)
    {
        $i=0;
        while($i<$n)
        {
            if(preg_match_all($this->timeregex,$fp1[$i],$result))
            {
                $res=$result[0][0];
                if(preg_match_all($this->pregnum,$res,$r))
                {
                    $one=$r[0][0];
                    $two= $r[0][1];
                    $three= $r[0][2];

                    if(isset($one,$two,$three))
                    {
                        $total=($one+$two+$three)/3;                 
                    }
                    elseif(isset($one,$two))
                    {
                        $total=($one+$two)/2;                        
                    }             
                    else
                    {                   
                        $total=$one;                        
                    }             
                }
            }            
            return $total;          
            $i++;
        }
    }
}

$test1=new test();


$file="file.txt";
$fp = file($file);
$n2=count($fp)-1;

echo "<table>";
while($i2<$n2-1)
{
    $i2++;
  
    echo "<tr>";
    echo "<td>".$i2 ."</td>";
    echo "<td>" . $test1->count($n2,$fp). "</td>";
    echo "</tr>";
}

echo "</table>";


#2 thevictorchen

thevictorchen
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 September 2008 - 03:37 AM

You seem to be calling the class function correctly. Just to be sure, I would verify that the function returns a value in all cases. You can do this by simply returning a dummy value at the very end of the function if for some reason $n <= $i.
Victor's Programming Aid - for C#, PHP, HTML, and SQL tutorials




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users