Jump to content

Display return value problem


crossline

Recommended Posts

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 :

[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>";
[/code]
Link to comment
Share on other sites

  • 2 years later...
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.