close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Nested repeat - set repeat filter based on parent results

Thread began 3/29/2022 7:39 am by Jared Lui | Last modified 3/30/2022 2:30 pm by Ray Borduin | 317 views | 4 replies |

Jared Lui

Nested repeat - set repeat filter based on parent results

Please view this db fiddle: https://dbfiddle.uk/?rdbms=mysql_5.6&fiddle=e08a34fc3ee453fa6cb6f3ed0e2ae025 if needed.

I have a table called: users
> userID | userFirstname | userLastName
> -----: | :------------ | :-----------
> 1 | John | Smith
> 2 | Alice | Jones
> 3 | Rob | Miller
> 4 | Ted | Kennedy
> 5 | Marty | Knight

A table called: eventDetails
> eventID | eventTitle | startDate | endDate
> ------: | :--------- | :--------- | :---------
> 1 | Event A | 2022-03-27 | 2022-03-28
> 2 | Event B | 2022-03-27 | 2022-03-31
> 3 | Event C | 2022-03-29 | 2022-03-29

And a table called: eventPersonnel
> eventID | userID
> ------: | -----:
> 1 | 1
> 1 | 3
> 1 | 2
> 2 | 4
> 2 | 5
> 3 | 2
> 3 | 4


-------------------------------------------------------------------------------------------------------------------------------------
I need to return all of the events for the logged in user where the events are within the current date. In the example DB I return 2 rows (eventID's 2 and 3).
I have these repeating correctly.

> -- This is my parent query. My actual WHERE statement uses a $_SESSION userID
> -- This needs to repeat for each event this sessions userID has within this time period
> SELECT *
> FROM eventDetails ed, eventPersonnel ep
> WHERE ep.userID = 4
> AND ed.eventID = ep.eventID
> AND CURDATE() BETWEEN ed.startDate AND ed.endDate
> ;
>
> <pre>
> eventID | eventTitle | startDate | endDate | eventID | userID
> ------: | :--------- | :--------- | :--------- | ------: | -----:
> 2 | Event B | 2022-03-27 | 2022-03-31 | 2 | 4
> 3 | Event C | 2022-03-29 | 2022-03-29 | 3 | 4

-------------------------------------------------------------------------------------------------------------------------------------
I also need to return all of the other users that belong to each of the returned event rows. So basically need to repeat the results of this SELECT statement within the repeat above.

> -- This is the child query.
> -- need to next repeat all rows of users for each of the returned events in the parent repeat
> -- The desired results should repeat the rows WHERE the eventID = the eventID from the repeating parent
> SELECT userFirstName, userLastName
> FROM users u
> JOIN eventPersonnel ep ON ep.userID = u.userID
> WHERE ep.eventID = 2
>
> <pre>
> userFirstName | userLastName
> :------------ | :-----------
> Ted | Kennedy
> Marty | Knight
------------------------------------------------------------------------------------------------------------------------------------
Results should look like this (omitted some columns for clarity):

Event B - 3/27/2022 - 3/31/2022
Ted Kennedy
Marty Knight

Event C - 3/29/2022 - 3/29/2022
Alice Jones
Ted Kennedy
------------------------------------------------------------------------------------------------------------------------------------
The attached screenshot shows the output as it works now.

The code below works as it should. However I have the eventID in the WHERE clause hard coded to make sure it does work for testing. But of course it repeats the same rows for both event. I don't know how to code it so that the WHERE eventID = (the returned eventID from the parent repeat). Im sure that it's some parameter in PHP that needs to be declared or something. It's been several years since I've done this and don't recall how. I've also tried several version of JOINS, UNIONS and GROUP BY. Perhaps there's something new in MySQLi that handles this now?
------------------------------------------------------------------------------------------------------------------------------------
<?php
$wa_repeatfor = -1; // Repeat Selection 1
if (!isset($wa_repeatcount)) $wa_repeatcount = 0;
while (!$currentEvents->atEnd() && $wa_repeatfor != 0) {
$wa_repeatfor--;
$wa_repeatcount++;
if (!$currentEvents->atEnd()) {
?>
<dl>
<dt><?php echo(($currentEvents->getColumnVal("start"))?date('n/d/Y',strtotime($currentEvents->getColumnVal("start"))):''); ?> - <?php echo(($currentEvents->getColumnVal("end"))?date('n/d/Y',strtotime($currentEvents->getColumnVal("end"))):''); ?></dt>
<dd><h4><?php echo($currentEvents->getColumnVal("title")); ?></h4>
<h5><?php echo($currentEvents->getColumnVal("description")); ?></h5></dd>
<dd><?php echo($currentEvents->getColumnVal("location")); ?> - <?php echo($currentEvents->getColumnVal("client")); ?></dd>
</dl>

<!--PERSONNEL REPEAT START-->
<?php
$rsPersonnel = new WA_MySQLi_RS("rsPersonnel",$stapleton,0);
$rsPersonnel->setQuery("SELECT u.UserFirstName FROM users u JOIN eventPersonnel ep ON ep.userID = u.UserID WHERE eventID = 27");
$rsPersonnel->execute();
?>
<?php
$wa_startindex = 0;
while(!$rsPersonnel->atEnd()) {
$wa_startindex = $rsPersonnel->Index;
?>
<dd><?php echo($rsPersonnel->getColumnVal("UserFirstName")); ?></dd>
<?php
$rsPersonnel->moveNext();
}
$rsPersonnel->moveFirst(); //return RS to first record
unset($wa_startindex);
unset($wa_repeatcount);
?>
<!--PERSONNEL REPEAT END-->

<?php
if ($wa_repeatfor != 0) $currentEvents->moveNext(); // Repeat Alternate 1
} else {
?>
<?php
} // End Repeat Alternate 1
?>
<?php
}
if (!isset($wa_startindex)) $currentEvents->moveFirst(); // End Repeat Selection 1
?>

Thanks in advance for any help!

Sign in to reply to this post

Ray BorduinWebAssist

Copy and paste your participants recordset inside the repeat region for the events. Then you can filter it based on the row from the events table and it will be re-created for each row and have the corresponding events.

Sign in to reply to this post
Did this help? Tips are appreciated...

Jared Lui

Originally Said By: Ray Borduin
  - you can filter it based on the row from the events table  



I Know this is wrong but it does pass code, just does not filter by the eventID of that event. It works if I hard code it. So how do I format this or am I way off?

<?php
$wa_repeatfor = -1; // Repeat Selection 1
if (!isset($wa_repeatcount)) $wa_repeatcount = 0;
while (!$currentEvents->atEnd() && $wa_repeatfor != 0) {
$wa_repeatfor--;
$wa_repeatcount++;
if (!$currentEvents->atEnd()) {

$rsPersonnel = new WA_MySQLi_RS("rsPersonnel",$stapleton,0);
$rsPersonnel->setQuery("SELECT u.UserFirstName FROM users u JOIN eventPersonnel ep ON ep.userID = u.UserID WHERE eventID = $currentEvents->getColumnVal(eventID) ");
$rsPersonnel->execute();
?>

Sign in to reply to this post

Ray BorduinWebAssist

$rsPersonnel = new WA_MySQLi_RS("rsPersonnel",$stapleton,0);
$rsPersonnel->setQuery("SELECT u.UserFirstName FROM users u JOIN eventPersonnel ep ON ep.userID = u.UserID WHERE eventID = ".$currentEvents->getColumnVal("eventID") ."");
$rsPersonnel->execute();

Just call me using the number at the bottom of every webassist.com page and we can set up a screen sharing session if you want to get a premier support ticket.

Sign in to reply to this post
Did this help? Tips are appreciated...

Jared Lui

Thanks Ray!

I'll get some questions together soon and set up a support ticket.

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...