close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

mySQLi Repeat Region, how to do a nested Repeat Region?

Thread began 7/07/2014 3:56 pm by Steve | Last modified 7/08/2014 9:55 am by Steve | 3047 views | 2 replies |

Steve

mySQLi Repeat Region, how to do a nested Repeat Region?

Possible?

Got a region that first selects ParentId and Title then sets an ID veriable to use in a sub query to select all Sibilngs (the usual stuff...).


<?php
while(!$rsParent->atEnd()) {
?>




<strong><?php echo($rsParent->getColumnVal("typeName")); ?></strong><br />



<?php $subtarget = ($rsParent->getColumnVal("typeId"));
echo 'subtarget : ' .$subtarget; ?>
<br />



<?php
$rsSiblings = new WA_MySQLi_RS("rsSiblings",$rtk_i,1);
$rsSiblings->setQuery("SELECT tblinvtype.typeId, tblinvtype.typeName FROM tblinvtype WHERE tblinvtype.`typeSibling` = ?");
$rsSiblings->bindParam("i", "".$subtarget ."", "75"); //target
$rsSiblings->execute();
?>

<ul>
<?php
while(!$rsSiblings->atEnd()) {
?>


<li><a href=#"><?php echo($rsSiblings->getColumnVal("typeName")); ?></a></li>


<?php
$rsSiblings->moveNext();
}
?>

</ul>

<?php
$rsParent->moveNext();
}
?>
Sign in to reply to this post

CraigRBeta Tester

Don't know if this helps, but a while ago, I read about creating a 'nested' repeat with a single recordset. - and I use this technique quite a bit.

Unfortunately I can't find the link to the article, so I dug up an old example and updated it to work with mysqli

The technique is to order the recordset by the 'parent' and then use a php if block to display the parent if it is different to the previous row, otherwise put a non breaking space.

It works fine in a table, you may be able to use the same logic

eg

<?php $previous = "";?>
<table>
<tr>
<th>Parent</th>
<th>Child</th>
</tr>
<?php
while(!$Recordset1->atEnd()) {
?>
<tr>
<td>
<?php
// display field if it doesn't match previous value
if ($Recordset1->getColumnVal("Parent") != $previous) {
echo $Recordset1->getColumnVal("Parent"); ?>

<?php
} else {
// otherwise, insert a non-breaking space
echo '&nbsp;';
}
// set $previous to current value for next time
$previous = $Recordset1->getColumnVal("Parent");
?>
<td>
<td><?php echo($Recordset1->getColumnVal("Child")); ?>
<td>

<?php
$Recordset1->moveNext();
}
$Recordset1->moveFirst(); //return RS to first record
?>
</tr>
</table>
Sign in to reply to this post

Steve

Thanks CraigR,

I can loop a recordset AND use an inner var using this method:

<?php
$sql="SELECT tblinvtype.typeId, tblinvtype.typeName FROM tblinvtype WHERE tblinvtype.`typeSibling` = ?";
echo $subtarget = ($rsParent->getColumnVal("typeId"));


/* Prepare statement */
$stmt = $rtk_i->prepare($sql);
if($stmt === false) {
trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $rtk_i->error, E_USER_ERROR);
}

/* Bind parameters. TYpes: s = string, i = integer, d = double, b = blob */
$stmt->bind_param('i',$subtarget);

/* Execute statement */
$stmt->execute();

?>




<?php
$stmt->bind_result($typeId, $typeName);
while ($stmt->etch()) {
echo $typeId. ', ' . $typeName . '<br>';
}
?>



Referenced in this article:
http://www.pontikis.net/blog/how-to-use-php-improved-mysqli-extension-and-why-you-should

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