close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

nested repeat regions

Thread began 4/20/2011 2:29 am by acaciasd344844 | Last modified 4/29/2011 7:35 am by Jason Byrnes | 4504 views | 7 replies |

acaciasd344844

nested repeat regions

Hi I wonder if you can help?

I have been playing around with nested repeat regions and dont seem to be able to make it work. The page should display multiple invoices and each invoice should contain multiple products. I checked some of the other posts but couldn't find anything similar. Thanks

Here is the code for the page in question

<?php
// RepeatSelectionCounter_2 Begin Loop
$RepeatSelectionCounter_2_IterationsRemaining = $RepeatSelectionCounter_2_Iterations;
while($RepeatSelectionCounter_2_IterationsRemaining--){
if($RepeatSelectionCounterBasedLooping_2 || $row_Recordsetmultiprint){
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="30%" colspan="6"><table width="100%" border="0">
<tr>
<td width="30%"><form id="form1" name="form1" method="post" action="">
<div align="right">
<input name="logo" type="image" id="logo" src="<?php echo $row_Recordsetmultiprint['companylogo']; ?>" align="right" />
</div>
</form> </td>
<td width="64%"><div align="right"><?php echo $row_Recordsetmultiprint['compnameadd']; ?></div></td>
</tr>

</table></td>
</tr>

<tr>
<td colspan="6" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="3">
<tr>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
</tr>
<tr>
<td width="10%" nowrap="nowrap">&nbsp;</td>
<td width="10%" nowrap="nowrap">Invoice Date:</td>
<td width="83%" nowrap="nowrap"><?php echo $row_Recordsetmultiprint['printdate']; ?></td>
</tr>
<?php if ($totalRows_Recordsetdisplayinvoiceid > 0) { // Show if recordset not empty ?>
<tr>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">Invoice Number:</td>
<td nowrap="nowrap"><?php echo $row_Recordsetmultiprint['invoiceid']; ?></td>
</tr>
<?php } // Show if recordset not empty ?>

<tr>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap"><strong>Account Ref:</strong></td>
<td nowrap="nowrap"><strong><?php echo $row_Recordsetmultiprint['customerid']; ?></strong></td>
</tr>
<tr>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
</tr>
<tr>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">To:</td>
<td nowrap="nowrap"><?php echo $row_Recordsetmultiprint['cust_name']; ?></td>
</tr>
<tr>
<td valign="top" nowrap="nowrap">&nbsp;</td>
<td valign="top" nowrap="nowrap">Address:</td>
<td nowrap="nowrap"><?php echo $row_Recordsetmultiprint['cust_houseno']; ?>&nbsp;<?php echo $row_Recordsetmultiprint['cust_street']; ?></td>
</tr>
<tr>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap"><?php echo $row_Recordsetmultiprint['district']; ?></td>
</tr>
<tr>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap"><?php echo $row_Recordsetmultiprint['town']; ?></td>
</tr>
<tr>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap"><?php echo $row_Recordsetmultiprint['postcode']; ?></td>
</tr>


<tr>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
</tr>
<tr>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap"><div align="center" class="style2">
<div align="left">Invoice</div>
</div></td>
<td nowrap="nowrap">&nbsp;</td>
</tr>
<tr>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
</tr>
<tr>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
</tr>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="8%">&nbsp;</td>
<td><table width="100%" border="0" align="left" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
<tr>
<td nowrap="nowrap"><div align="left"><?php echo $row_Recordsetmultiprint['title1']; ?></div></td>
<td nowrap="nowrap"><div align="left"><?php echo $row_Recordsetmultiprint['title2']; ?></div></td>
<td nowrap="nowrap"><div align="left"><?php echo $row_Recordsetmultiprint['title3']; ?></div></td>
<td nowrap="nowrap"><div align="right"><?php echo $row_Recordsetmultiprint['title4']; ?></div></td>
<td nowrap="nowrap"><div align="right"><?php echo $row_Recordsetmultiprint['title5']; ?></div></td>
</tr>
<tr>
<td colspan="5" nowrap="nowrap"><hr /></td>
</tr>
<?php
// RepeatSelectionCounter_1 Begin Loop
$RepeatSelectionCounter_1_IterationsRemaining = $RepeatSelectionCounter_1_Iterations;
while($RepeatSelectionCounter_1_IterationsRemaining--){
if($RepeatSelectionCounterBasedLooping_1 || $row_Recordsetdisplayproducts){
?>
<tr>
<td nowrap="nowrap"><?php echo $row_Recordsetdisplayproducts['product1']; ?></td>
<td nowrap="nowrap"><?php echo $row_Recordsetdisplayproducts['product2']; ?></td>
<td nowrap="nowrap"><?php echo $row_Recordsetdisplayproducts['product3']; ?></td>
<td nowrap="nowrap"><div align="right"><?php echo $row_Recordsetdisplayproducts['product4']; ?></div></td>
<td nowrap="nowrap"><div align="right"><?php echo $row_Recordsetdisplayproducts['product5']; ?></div></td>
</tr>
<?php
} // RepeatSelectionCounter_1 Begin Alternate Content
else{
?>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<?php } // RepeatSelectionCounter_1 End Alternate Content
if(!$RepeatSelectionCounterBasedLooping_1 && $RepeatSelectionCounter_1_IterationsRemaining != 0){
if(!$row_Recordsetdisplayproducts && $RepeatSelectionCounter_1_Iterations == -1){$RepeatSelectionCounter_1_IterationsRemaining = 0;}
$row_Recordsetdisplayproducts = mysql_fetch_assoc($Recordsetdisplayproducts);
}
$RepeatSelectionCounter_1++;
} // RepeatSelectionCounter_1 End Loop
?>
<tr>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
</tr>
</table>
<table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td><hr /></td>
</tr>
<tr>
<td><?php echo $row_Recordsetmultiprint['notes']; ?></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><div align="justify"><?php echo $row_Recordsetmultiprint['invoicetxtcomm']; ?></div></td>
</tr>
</table></td>
</tr>
</table> </td>
</tr>
<tr>
<td colspan="6" valign="top">&nbsp;</td>
</tr>
<tr>
<td colspan="6" valign="top">&nbsp;</td>
</tr>
<tr>
<td colspan="6" valign="top"><hr /></td>
</tr>
<tr>
<td colspan="6" valign="top"><hr /></td>
</tr>
</table>
<?php
} // RepeatSelectionCounter_2 Begin Alternate Content
else{
?>
<?php } // RepeatSelectionCounter_2 End Alternate Content
if(!$RepeatSelectionCounterBasedLooping_2 && $RepeatSelectionCounter_2_IterationsRemaining != 0){
if(!$row_Recordsetmultiprint && $RepeatSelectionCounter_2_Iterations == -1){$RepeatSelectionCounter_2_IterationsRemaining = 0;}
$row_Recordsetmultiprint = mysql_fetch_assoc($Recordsetmultiprint);
}
$RepeatSelectionCounter_2++;
} // RepeatSelectionCounter_2 End Loop
?>

Sign in to reply to this post

Jason ByrnesWebAssist

when working with nested repeat regions, you need to do some code rearanging.

the recordset code for the second repeat region needs to be moved inside of the first repeat region.

Sign in to reply to this post

acaciasd344844

Not sure what you mean

This is the code for the second repeat region...

mysql_select_db($database_midas0001, $midas0001);
$query_Recordsetdisplayproducts = sprintf("SELECT * FROM products WHERE invoiceid = %s ORDER BY productid", GetSQLValueString($colname2_Recordsetdisplayproducts, "int"));
$Recordsetdisplayproducts = mysql_query($query_Recordsetdisplayproducts, $midas0001) or die(mysql_error());
$row_Recordsetdisplayproducts = mysql_fetch_assoc($Recordsetdisplayproducts);
$totalRows_Recordsetdisplayproducts = mysql_num_rows($Recordsetdisplayproducts);

and this is the code for the first repeat region...

mysql_select_db($database_midas0001, $midas0001);
$query_Recordsetmultiprint = "SELECT *, DATE_FORMAT(datecreated,'%d %M %Y') as printdate FROM invoice LEFT JOIN customers ON customers.customerid = invoice.invoiceid LEFT JOIN products ON products.invoiceid = invoice.invoiceid LEFT JOIN preferences ON customers.prefid = preferences.prefid WHERE invoice.print = '1' group by invoice.invoiceid";
$Recordsetmultiprint = mysql_query($query_Recordsetmultiprint, $midas0001) or die(mysql_error());
$row_Recordsetmultiprint = mysql_fetch_assoc($Recordsetmultiprint);
$totalRows_Recordsetmultiprint = mysql_num_rows($Recordsetmultiprint);?>

So, do you mean add the two codes together within the php brackets like so...

mysql_select_db($database_midas0001, $midas0001);
$query_Recordsetmultiprint = "SELECT *, DATE_FORMAT(datecreated,'%d %M %Y') as printdate FROM invoice LEFT JOIN customers ON customers.customerid = invoice.invoiceid LEFT JOIN products ON products.invoiceid = invoice.invoiceid LEFT JOIN preferences ON customers.prefid = preferences.prefid WHERE invoice.print = '1' group by invoice.invoiceid";
$Recordsetmultiprint = mysql_query($query_Recordsetmultiprint, $midas0001) or die(mysql_error());
$row_Recordsetmultiprint = mysql_fetch_assoc($Recordsetmultiprint);
$totalRows_Recordsetmultiprint = mysql_num_rows($Recordsetmultiprint);mysql_select_db($database_midas0001, $midas0001);
$query_Recordsetdisplayproducts = sprintf("SELECT * FROM products WHERE invoiceid = %s ORDER BY productid", GetSQLValueString($colname2_Recordsetdisplayproducts, "int"));
$Recordsetdisplayproducts = mysql_query($query_Recordsetdisplayproducts, $midas0001) or die(mysql_error());
$row_Recordsetdisplayproducts = mysql_fetch_assoc($Recordsetdisplayproducts);
$totalRows_Recordsetdisplayproducts = mysql_num_rows($Recordsetdisplayproducts);?>

as i cant see it making a difference or have I got the wrong end of the stick.

sorry for being such a numskull

thanks

john

Sign in to reply to this post

Jason ByrnesWebAssist

No, I do not mean combine the recordset code.


I mean that recordset code that drives the second repeat region must be moved so that it is inside the 1st repeat repeat region code in the body of the page.


you also need to set it to filter the foregin key column on the primary key value from the first recordset.

Sign in to reply to this post

acaciasd344844

nested repeat

Hi Jason,

I have managed at last to get the recordset in the right place and the page is starting to come together. I am having trouble with the relationship though.

When our customers decide how many invoices they need to print up to 50 in some cases, they can mark the invoices they wish to print by putting a tick in a box. When these details are ready to be printed the recordset is searched by looking for the boolean tick which is a value of 1. The requested records are then displayed in invoiceid order. Recordset code below...

SELECT *, DATE_FORMAT(datecreated,'%d %M %Y') as printdate
FROM invoice
LEFT JOIN customers ON customers.customerid = invoice.customerid
LEFT JOIN products ON products.invoiceid = invoice.invoiceid
LEFT JOIN preferences ON customers.prefid = preferences.prefid
WHERE invoice.print = '1'
GROUP BY invoice.invoiceid

the nested loop

The second recordset should search for the actual products that should be associated with the relevant invoice, but I am not sure how to link them as the first recordset is using the boolean value as the search criteria. And if I do use that value, it simply displays all the products on every invoice. Recordset code below...

SELECT *
FROM products left join invoice on invoice.invoiceid = products.invoiceid
WHERE invoice.print = '1'
ORDER BY productid

I fully realise that I should use the primary key to link the two repeat regions but I cannot see how I can manage this. Is there another method that I could use?

Any help would be really appreciated


john

Sign in to reply to this post

Jason ByrnesWebAssist

on the second recordset add to the where clause:


WHERE products.invoiceid = paramInvoiceID AND invoice.print = '1'


then crate a new parameter:
Name: paramInvoiceID
type: Number
default value: -1
RunTime value: $row_FirstRSName['invoiceid']


where "FirstRSName" is the name of the first recordset.

Sign in to reply to this post

acaciasd344844

Thanks

Originally Said By: Jason Byrnes
  on the second recordset add to the where clause:


WHERE products.invoiceid = paramInvoiceID AND invoice.print = '1'


then crate a new parameter:
Name: paramInvoiceID
type: Number
default value: -1
RunTime value: $row_FirstRSName['invoiceid']


where "FirstRSName" is the name of the first recordset.  



Just like to say a big thank you Jason cheers

john

Sign in to reply to this post

Jason ByrnesWebAssist

You're welcome.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...