Forums
This topic is locked
Nested Repeat Region & MySQL Join's
Posted 12 Oct 2001 00:31:23
1
has voted
12 Oct 2001 00:31:23 Stephen Bateman posted:
I have managed to work out how to join two tables together with MySQL using the following code:SELECT v.*, u.*
FROM video AS v, user AS u
WHERE v.user_id = u.user_id
ORDER BY v.user_id
Which returns a list of all fields in both tables so long as the video table has a record that matches the users_id.
I can then list all the records in a standard repeat region fine. However I would like to group all the video records for a particular user together.
User Name 1
- Video 1
- Video 2
User Name 2
- Video 1
- Video 2
The problem need help on is getting the video repeat region to work while maintaining the overall Next Record order. I get limited success from the following code, but some records just seem to disappear. If anyone has time to comment and give me pointers I would appreciate it.
<pre id=code><font face=courier size=2 id=code>
<?php while (($Repeat1__numRows-- != 0) && (!$rs_uservideoss->EOF))
{
$lastuser = $rs_uservideoss->Fields("user_id"
$nextuser = $rs_uservideoss->Fields("user_id"
?>
<table width="700" border="0">
<tr>
<td colspan="2"> <font face="Arial, Helvetica, sans-serif">
<font size="2"> <b>
<?php echo $rs_uservideoss->Fields("peudonym"?>
of
<?php echo $rs_uservideoss->Fields("base"?>
</b></font></font> </td>
</tr>
<?php while ($lastuser == $nextuser)
{
?>
<tr>
<td width="200" align="center" valign="middle">
<div align="center"><img src="<?php echo $rs_uservideoss->Fields("thumburl"?>" width="160" height="120" alt="Click to play" border="0"></div>
</td>
<td width="250" align="center" valign="middle">
<div align="center"><font size="2"> </font>
<table width="350" border="0" align="center">
<tr>
<td width="50"><font size="2" face="Arial, Helvetica, sans-serif">Title:</font></td>
<td width="200"><font face="Arial, Helvetica, sans-serif"><font size="2">
<?php echo $rs_uservideoss->Fields("title"?>
</font></font></td>
<td width="100">
<div align="center"><font face="Arial, Helvetica, sans-serif">
<font size="2"> </font></font> </div>
</td>
</tr>
<tr>
<td width="50"> </td>
<td width="200"> </td>
<td width="100">
<div align="center"><a href="javascript:;" onClick="GP_AdvOpenWindow('/members/playvideo.php?video_id=<?php echo $rs_uservideoss->Fields("video_id"?>','PlayVideo','fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no',375,425,'center','ignoreLink','alwaysOnTop',300,'borderless');return document.MM_returnValue"><img src="/images/buttons/100x20/playvideo.gif" width="100" height="20" alt="Play Video" onMouseDown="GP_AdvOpenWindow('/members/playvideo.php?video_id=<?php echo $rs_uservideoss->Fields("video_id"?>','PlayVideo','fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no',375,425,'center','ignoreLink','alwaysOnTop',300,'borderless');return document.MM_returnValue" border="0"></a></div>
</td>
</tr>
<tr>
<td width="50"><font face="Arial, Helvetica, sans-serif" size="2">Length:</font>
</td>
<td width="200"><font face="Arial, Helvetica, sans-serif"><font size="2">
<?php echo $rs_uservideoss->Fields("length"?>
Seconds </font></font></td>
<td width="100">
<div align="center"><font face="Arial, Helvetica, sans-serif">
<font size="2"> </font></font></div>
</td>
</tr>
</table>
</div>
</td>
<?php
$Repeat2__index++;
$lastuser = $rs_uservideoss->Fields("user_id"
$rs_uservideoss->MoveNext();
$nextuser = $rs_uservideoss->Fields("user_id"
}
?>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<?php
$Repeat1__index++;
$rs_uservideoss->MoveNext();
}
?>
</font id=code></pre id=code>
Replies
Replied 12 Oct 2001 15:31:32
12 Oct 2001 15:31:32 Bruno Mairlot replied:
Unfortunately it is not (yet) possible to do nested repeated region (to my knowledge)
My suggestion would be to add a little piece of code that would detect if the User Name has changed in the recordset, and then print it, otherwise don't print it.
Here's how I do that :
<pre id=code><font face=courier size=2 id=code>
<?php
$oldUserName="";
?>
<?php while (($Repeat1__numRows-- != 0) && (!$rs_uservideoss->EOF)) {
?>
<font color=red>.
.
.</font id=red>
<?php
if($oldUserName!=$rs_uservideoss->Fields("user_id"){
echo $rs_uservideoss->Fields("user_id"
}
?>
<font color=red>.
.
.</font id=red>
<?php
$oldUserName = $rs_uservideoss->Fields("user_id"
?>
// End of loop for repeat region 1
<?php $Repeat1__index++; $rs_uservideoss->MoveNext();}?>
</font id=code></pre id=code>
So the first step is to initialize $oldUserName to a value you're sure not having in your database
Next you start the loop for the repeat region, and print the user_id only if it is different from the precedent row.
Hope it helps.
Bruno
--- Better to die trying, than never try at all ---
My suggestion would be to add a little piece of code that would detect if the User Name has changed in the recordset, and then print it, otherwise don't print it.
Here's how I do that :
<pre id=code><font face=courier size=2 id=code>
<?php
$oldUserName="";
?>
<?php while (($Repeat1__numRows-- != 0) && (!$rs_uservideoss->EOF)) {
?>
<font color=red>.
.
.</font id=red>
<?php
if($oldUserName!=$rs_uservideoss->Fields("user_id"){
echo $rs_uservideoss->Fields("user_id"
}
?>
<font color=red>.
.
.</font id=red>
<?php
$oldUserName = $rs_uservideoss->Fields("user_id"
?>
// End of loop for repeat region 1
<?php $Repeat1__index++; $rs_uservideoss->MoveNext();}?>
</font id=code></pre id=code>
So the first step is to initialize $oldUserName to a value you're sure not having in your database
Next you start the loop for the repeat region, and print the user_id only if it is different from the precedent row.
Hope it helps.
Bruno
--- Better to die trying, than never try at all ---