0

Hi,

Any body please help me out:

[B]  while loop
   {
      $val=mysql_num_rows($result14);
      $blnk=array();
      array_push($blnk,$val);
  }

$blnkarraysum=array_sum($blnk);
[/B]

Values are not at all getting add up. why ? thanks in advance

3
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by cereal
0

You need session, otherwise the array will become empty after each loop. This should work:

<?php 
    session_start();
    while loop
    {
       $blnk = ($_SESSION['numRows'] == NULL) array() : $_SESSION['numRows'];
       $val=mysql_num_rows($result14);
       array_push($blnk,$val);
       if($_SESSION['numRows'] == NULL) { $_SESSION['numRows'] = $blnk; } # start session
    }
    #$blnkarraysum=array_sum($blnk);
    $blnkarraysum = $blnk;
?>

Edited by cereal: n/a

1

this doesn't appear to have anything to do with sessions. you need to initialize $blnk array outside your loop. otherwise you are constantly overwriting what is held in $blnk every time you pass over it in the while loop.

$blnk=array();
while loop
   {
      $val=mysql_num_rows($result14);
      array_push($blnk,$val);
  }

$blnkarraysum=array_sum($blnk);
0

@ddymacek

You're right. I had just woken up, when I wrote my post, and thinking for some strange reason to a form increasing a value o_o'

Pardon for bad suggestion.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.