Skip to main content
Known Participant
May 28, 2009
Answered

Forcing line break in repeating region

  • May 28, 2009
  • 2 replies
  • 943 views

I've got a table that's displaying some data from a query in PHP that I made using a simple Recordset and Repeat Region behavior.  I would really like to be able to break the table up (add blank row) each time a certain field changes values.  My code (or the code DW gave me) is as follows.

  <?php do { ?>

      <tr bgcolor="#809E7C" class="reg_dataview_data">

        <td>  </td>

        <td><?php echo $row_rs_Sum09['ChildFirst']; ?></td>

        <td><?php echo $row_rs_Sum09['ChildAge']; ?></td>

        <td><?php echo $row_rs_Sum09['ChildSex']; ?></td>

        <td><?php echo $row_rs_Sum09['Session']; ?></td>

        <td><?php echo $row_rs_Sum09['Status']; ?></td>

        <td><?php echo $row_rs_Sum09['Quarter']; ?></td>

      </tr>

      <?php } while ($row_rs_Sum09 = mysql_fetch_assoc($rs_Sum09)); ?>

I'd like for the table to break at change in value of Session.

Any tips would be greatly appreciated.

Steve

This topic has been closed for replies.
Correct answer David_Powers

Yes, sorry about that. Simple mistake. I forgot to reset the value each time the loop runs:

      <?php // get the initial value of session
      $currentSession = $row_rs_Sum09['Session'];
      do {
      // create empty row if session is different
      if ($row_rs_Sum09['Session'] != $currentSession) {
      ?>
      <tr><td colspan="7"> </td></tr>
      <?php } ?>
      <tr bgcolor="#809E7C" class="reg_dataview_data">
        <td>  </td>
        <td><?php echo $row_rs_Sum09['ChildFirst']; ?></td>
        <td><?php echo $row_rs_Sum09['ChildAge']; ?></td>
        <td><?php echo $row_rs_Sum09['ChildSex']; ?></td>
        <td><?php echo $row_rs_Sum09['Session']; ?></td>
        <td><?php echo $row_rs_Sum09['Status']; ?></td>
        <td><?php echo $row_rs_Sum09['Quarter']; ?></td>
      </tr>
      <?php
      // update the value of $currentSession
      $currentSession = $row_rs_Sum09['Session'];
      } while ($row_rs_Sum09 = mysql_fetch_assoc($rs_Sum09)); ?>

By the way, attaching images is very hit and miss in this forum. It's much better to use the camera icon at the top of the message field to embed the image directly in your post.

2 replies

David_Powers
Inspiring
May 28, 2009

You need to create a variable to compare the value of Session with the existing one.

      <?php // get the initial value of session

      $currentSession = $row_rs_Sum09['Session'];

      do {

      // create empty row if session is different

      if ($row_rs_Sum09['Session'] != $currentSession) {

      ?>

      <tr><td colspan="7"> </td></tr>

      <?php } ?>

      <tr bgcolor="#809E7C" class="reg_dataview_data">

        <td>  </td>

        <td><?php echo $row_rs_Sum09['ChildFirst']; ?></td>

        <td><?php echo $row_rs_Sum09['ChildAge']; ?></td>

        <td><?php echo $row_rs_Sum09['ChildSex']; ?></td>

        <td><?php echo $row_rs_Sum09['Session']; ?></td>

        <td><?php echo $row_rs_Sum09['Status']; ?></td>

        <td><?php echo $row_rs_Sum09['Quarter']; ?></td>

      </tr>

      <?php } while ($row_rs_Sum09 = mysql_fetch_assoc($rs_Sum09)); ?>

SJurickAuthor
Known Participant
May 29, 2009

Hi David.  Thank you.  It's much closer now.  I get a blank row after the first grouping of Sessions of the same value as expected, then every row after that has one row of data, and a blank below it, regardless of if the Session value is the same or not, like it's not checking the variable after the first run through?  See attached file...

David_Powers
David_PowersCorrect answer
Inspiring
May 30, 2009

Yes, sorry about that. Simple mistake. I forgot to reset the value each time the loop runs:

      <?php // get the initial value of session
      $currentSession = $row_rs_Sum09['Session'];
      do {
      // create empty row if session is different
      if ($row_rs_Sum09['Session'] != $currentSession) {
      ?>
      <tr><td colspan="7"> </td></tr>
      <?php } ?>
      <tr bgcolor="#809E7C" class="reg_dataview_data">
        <td>  </td>
        <td><?php echo $row_rs_Sum09['ChildFirst']; ?></td>
        <td><?php echo $row_rs_Sum09['ChildAge']; ?></td>
        <td><?php echo $row_rs_Sum09['ChildSex']; ?></td>
        <td><?php echo $row_rs_Sum09['Session']; ?></td>
        <td><?php echo $row_rs_Sum09['Status']; ?></td>
        <td><?php echo $row_rs_Sum09['Quarter']; ?></td>
      </tr>
      <?php
      // update the value of $currentSession
      $currentSession = $row_rs_Sum09['Session'];
      } while ($row_rs_Sum09 = mysql_fetch_assoc($rs_Sum09)); ?>

By the way, attaching images is very hit and miss in this forum. It's much better to use the camera icon at the top of the message field to embed the image directly in your post.

DwFAQ
Participating Frequently
May 28, 2009

Whatever you put in the repeat region will be repeated. Add a conditional region if field changed show break else.

SJurickAuthor
Known Participant
May 28, 2009

I'm afraid I'm not good at PHP, I just tweak what DW makes for me here and there so is there somewhere you can point me that has examples of what I'm trying to do?  I tried searching Google but am having trouble finding what I need.  I dont' suppose DW has this functionality built in?

DwFAQ
Participating Frequently
May 28, 2009

for conditional region look here

also check out http://php.net