0

I am creating a student fee management form. My fee_inventory table includes fields id, fee_name, amount, fee_type, class, session

fee_type field can be monthly, quarterly, halfyearly, annually

Now I want to display a table where for each fee_name there will be 12 months

If fee_type='quarterly' rowspan='3' If fee_type='halfyearly' rowspan='6' and for annually rowspan will be 12

my php code is given below which is printing an abnormal table. Once it gets rowspan=3 it should not print the particular for the next two values of $i.

Help me in getting it correct

<?php
    echo '<table border="2"><tr>';

    while($row4=mysql_fetch_array($result4))
    {
      echo '<td>'.$row4[1].'</td>';
    }
    echo '</tr>';
    $data = array();

    while( $row5 = mysql_fetch_array($result5) )
    $data[] = $row5;

    for($i=1;$i<=12;$i++)
    {
        echo '<tr>';
        foreach ( $data as $row5 ) 
        {

          if($row5[3]=='monthly')
          echo '<td>'.$row5[3].'</td>';
          else if($row5[3]=='quarterly')
          echo '<td rowspan="3">'.$row5[3].'</td>';
          else if($row5[3]=='halfyearly')
          echo '<td rowspan="6">'.$row5[3].'</td>';
          else if( $row5[3]=='anually')
          echo '<td rowspan="12">'.$row5[3].'</td>';
        }
        echo '</tr>';
     }
     echo '</table>';
 ?>
4
  • What does the for loop have to do in this instance? It seems that you're just iterating the $data 12 more times than it should be...? Commented Jul 9, 2014 at 1:35
  • can u please clarify what do u mean by "Once it gets rowspan=3 it should not print the particular for the next two values of $i." Commented Jul 9, 2014 at 1:53
  • for loop is for 12 months... Commented Jul 10, 2014 at 11:21
  • if $row[3]=='quarterly' it prints a cell with rowspan=3. So for the loop that is running 12 times i just need this cell to print from loop variable value=1,4,7,10. This is the logic where I am stuck Commented Jul 10, 2014 at 11:22

1 Answer 1

1

I believe you are trying to do this

<?php
    echo '<table border="2"><tr>';

    while($row4=mysql_fetch_array($result4))
    {
      echo '<td>'.$row4[1].'</td>';
    }
    echo '</tr>';
    $data = array();

    while( $row5 = mysql_fetch_array($result5) )
    $data[] = $row5;
    echo '<tr>';
    foreach ( $data as $row5 ) 
    {
        if($row5[3]=='monthly') {
            echo '<td>'.$row5[3].'</td>';
            for($i=1;$i<=11;$i++)
            {
                echo '<td></td>';
            }
        }
        else if($row5[3]=='quarterly')
        {
            echo '<td rowspan="3">'.$row5[3].'</td>';
            for($i=1;$i<=4;$i++)
            {
                echo '<td rowspan="3"></td>';
            }
        }
        else if($row5[3]=='halfyearly')
        {
            echo '<td rowspan="6">'.$row5[3].'</td>';
            for($i=1;$i<=2;$i++)
            {
                echo '<td rowspan="6"></td>';
            }
        }
        else if( $row5[3]=='anually')
        {
            echo '<td rowspan="12">'.$row5[3].'</td>';
        }
        echo '</tr>';
    }
    echo '</table>';
 ?>
Sign up to request clarification or add additional context in comments.

1 Comment

Can u show me the screen shot of what is the outcome of it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.