Copy link to clipboard
Copied
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
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>
...
Copy link to clipboard
Copied
Whatever you put in the repeat region will be repeated. Add a conditional region if field changed show break else.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
for conditional region look here
also check out http://php.net
Copy link to clipboard
Copied
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)); ?>
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks David as always! That did the trick. I'll remember the camera icon for next time too.
Steve