MySQLI Nested Repeat
I've done nested repeat regions before, but that was many years ago and never with MySQLI - I was hoping for some help. I have two tables. 1) Articles which include fields id, adate, name, article. 2) Image with fields id, fk (foreign key back to articles), name. Each article can have multiple images.
Query for articles:
<?php
$rsArticle = new WA_MySQLi_RS("rsArticle",$connPIW2015_i,10);
$rsArticle->setQuery("SELECT article.id, article.adate, article.name FROM article");
$rsArticle->execute();
?>
I created a query for images, a repeat region for the articles, another repeat region for the images, then manually moved the images query and repeat regions into the articles repeat region, so the code looks like this.
<?php
while(!$rsArticle->atEnd()) {
?>
<?php
$rsImages = new WA_MySQLi_RS("rsImages",$connPIW2015_i,0);
$rsImages->setQuery("SELECT images.id, images.fk, images.name FROM images");
$rsImages->execute();
?>
<div><?php echo($rsArticle->getColumnVal("adate")); ?>,
<?php echo($rsArticle->getColumnVal("name")); ?>
<?php
while(!$rsImages->atEnd()) {
?>
<p><?php echo($rsImages->getColumnVal("name")); ?></p>
<?php
$rsImages->moveNext();
}
$rsImages->moveFirst(); //return RS to first record
?>
</div>
<?php
$rsArticle->moveNext();
}
$rsArticle->moveFirst(); //return RS to first record
?>
Not sure where to go from here. The rsImages query needs some sort of WHERE statement, but not sure what that is.
Please help,
Thanks - Jeff.