0

Dear all, I have a problem to count the total of receiving items.. but when I run this code I output of the total displayed "1".. not "5"...here my code.. hope someone can help me to count the total of receiving..

<?php
include 'connection/db_connect.php';
?>
<form name="form1" method="post" action="">
  <table width="357" height="42" border="1" cellspacing="0">
    <tr>
      <td width="132">Dept</td>
      <td width="108">Doc A</td>
      <td width="109">Doc B</td>
    </tr>
    <?php
    $sql = "SELECT l.doc_id, l.doc_name, l.receiver, d.dept_id, d.dept_name 
            FROM list l, dept d WHERE l.iso_cat='2' AND l.issuer=d.dept_id";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)) {
    $rec = $row['receiver'];
    $dept_rc=split(",",$rec);

    $d1 = '4';
    if(in_array($d1,$dept_rc) == TRUE){ //dp2
          $dc1="1"; } else $dc1="0";
          for($x=0; $x <= count($dc1['$x']); $x++)  {
                      }
    ?>
    <tr>
      <td><?php echo $row['dept_name']; ?></td>
      <td><?php echo $dc1; ?></td>
      <td>&nbsp;</td>
    </tr>
     <?php } ?>
    <tr>
      <td>Total</td>
      <td><?php echo count($dc1['$x']); ?></td> 
      <td>&nbsp;</td>
    </tr>

  </table>
</form>
3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by blocblue
0

hurm..for solution I just used SELECT COUNT(*) FROM table...
but I still want to try this way..if cannot just used SELECT COUNT()..

0

If u want count manually, then this is one solution ...

1) take $count=0;
2) Increment $count at the end of the while loop.
3) Print $count;

Code:

$count=0;
while($row = mysql_fetch_array($result)) {
    $rec = $row['receiver'];
    $dept_rc=split(",",$rec);
    $d1 = '4';
    if(in_array($d1,$dept_rc) == TRUE){ //dp2
          $dc1="1"; } else $dc1="0";
          for($x=0; $x <= count($dc1['$x']); $x++)  {
                      }
    ?>
    <tr>
      <td><?php echo $row['dept_name']; ?></td>
      <td><?php echo $dc1; ?></td>
      <td> </td>
    </tr>
     <?php $count++; } ?>
    <tr>
      <td>Total</td>
      <td><?php echo $count; ?></td> 
      <td> </td>
    </tr>
0

You could also use $count = mysql_num_rows($result); after line 14, but before the start of the while loop.

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.