Solved

Nested Repeat Region - Dreamweaver CS4 - PHP - MySQL

Posted on 2009-05-12
7
1,377 Views
Last Modified: 2012-05-06
Hi Experts

Would really appreciate some help with creating a nested repeat region. I am using Dreamweaver CS4 and the developer toolobox is no longer available. (wouldn't want to use it anyway!)

I am using the code below to group lists of students under dates. It is returning the correct result for the first loop but not for subsequent ones.

Would have been surprised it if was as easy as I've tried but may well use this in other areas of my current project so would really appreciate your expertise.

Many thanks
// Recordset to return list of dates

$grading_date_rsDateGroup = "2009-02-01";

if (isset($_GET['date'])) {

  $grading_date_rsDateGroup = $_GET['date'];

}

$print_stamp_rsDateGroup = "1";

if (isset($_GET['stamp'])) {

  $print_stamp_rsDateGroup = $_GET['stamp'];

}

mysql_select_db($database_connEACKDK, $connEACKDK);

$query_rsDateGroup = sprintf("SELECT g.date, g.id FROM gradings AS g        JOIN students s ON g.id = s.id JOIN print_queue p on g.id = p.student_id AND p.timestamp = %s WHERE g.timestamp = %s GROUP BY g.date ORDER BY g.date ASC", GetSQLValueString($print_stamp_rsDateGroup, "int"),GetSQLValueString($grading_date_rsDateGroup, "date"));

$rsDateGroup = mysql_query($query_rsDateGroup, $connEACKDK) or die(mysql_error());

$row_rsDateGroup = mysql_fetch_assoc($rsDateGroup);

$totalRows_rsDateGroup = mysql_num_rows($rsDateGroup);
 

// Recordset for nested repeat

$grading_date_rsGradersTest = "2009-02";

if (isset($_GET['date'])) {

  $grading_date_rsGradersTest = $_GET['date'];

}

$date_group_rsGradersTest = "2009-05-01";

if (isset($row_rsDateGroup['date'])) {

  $date_group_rsGradersTest = $row_rsDateGroup['date'];

}

$print_stamp_rsGradersTest = "1";

if (isset($_GET['stamp'])) {

  $print_stamp_rsGradersTest = $_GET['stamp'];

}

mysql_select_db($database_connEACKDK, $connEACKDK);

$query_rsGradersTest = sprintf("SELECT g.id,  g.date,  g.timestamp,  s.firstName,  s.lastname,  s.belt_size,  b1.belt AS current,   b2.belt AS new, DATE_FORMAT(g.date, '%%M %%Y') as fdate FROM gradings AS g        JOIN students s ON g.id = s.id  JOIN print_queue p on g.id = p.student_id AND p.timestamp = %s      LEFT OUTER JOIN belts b1 ON g.current = b1.id  LEFT OUTER JOIN belts b2 ON g.new = b2.id WHERE g.timestamp = %s AND g.date = %s ORDER BY g.date ASC, b1.id DESC, s.lastname ASC", GetSQLValueString($print_stamp_rsGradersTest, "int"),GetSQLValueString($grading_date_rsGradersTest, "date"),GetSQLValueString($date_group_rsGradersTest, "date"));

$rsGradersTest = mysql_query($query_rsGradersTest, $connEACKDK) or die(mysql_error());

$row_rsGradersTest = mysql_fetch_assoc($rsGradersTest);

$totalRows_rsGradersTest = mysql_num_rows($rsGradersTest);
 

// Nested repeat in HTML

<table width="97%" border="0" cellspacing="5" cellpadding="0">

  <tr>

    <td width="70%" valign="top"><table width="100%" border="1" cellspacing="0" cellpadding="5">

      <?php do { ?>

        <tr>

          <td><?php echo $row_rsDateGroup['date']; ?><br />

          <?php do { ?>

            <?php echo $row_rsGradersTest['firstName']; ?> <?php echo $row_rsGradersTest['lastname']; ?><br />

            <?php } while ($row_rsGradersTest = mysql_fetch_assoc($rsGradersTest)); ?>

            </td>

        </tr>

        <?php } while ($row_rsDateGroup = mysql_fetch_assoc($rsDateGroup)); ?>

    </table>

     </td>

    </tr>

</table>

Open in new window

0
Comment
Question by:sirnutty1
  • 3
  • 3
7 Comments
 
LVL 7

Expert Comment

by:Jonah11
ID: 24369413
Its not clear exactly how you want it displayed, but one thing i notice is that you open a <tr>  on line 37, then a <td> on 38 (everything ok so far), but now you open a new <tr> on 40 before the open <td> is closed.  are you trying to nest a table within a table?  if you could describe how you wanted the output to look exactly, i could better help.
0
 
LVL 5

Expert Comment

by:dhobale
ID: 24369994
Write your code in following format:

$result = mysql_query($query);

while($row = mysql_fetch_assoc($result))
{
    echo "<td>$row_rsDateGroup['date'];  <br>" .
         "next field...".

YOU should PUT YOUR 2nd loop here
}

0
 

Author Comment

by:sirnutty1
ID: 24374866
I'm getting myself a little confused!!

If I have the simplified code as below with just one DW repeat region, could you possibly give me an idea on how I would enter a nested repeat region that uses the date row from the parent repeat region as a variable?

Sincere thanks
//PHP

mysql_select_db($database_connEACKDK, $connEACKDK);

$query_rsDateGroup = "SELECT g.date, g.id FROM gradings AS g GROUP BY g.date ORDER BY g.date ASC";

$rsDateGroup = mysql_query($query_rsDateGroup, $connEACKDK) or die(mysql_error());

$row_rsDateGroup = mysql_fetch_assoc($rsDateGroup);

$totalRows_rsDateGroup = mysql_num_rows($rsDateGroup);
 

//HTML

<table width="97%" border="1" cellspacing="0" cellpadding="5">

      <?php do { ?>

  <tr>

    <td valign="top"><?php echo $row_rsDateGroup['date']; ?></td>

  </tr>

  <tr>

    <td valign="top">NESTED REPEAT REGION GOES HERE</td>

  </tr>

  <?php } while ($row_rsDateGroup = mysql_fetch_assoc($rsDateGroup)); ?>

  </table>

Open in new window

0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 7

Expert Comment

by:Jonah11
ID: 24376861
sirnutty,

i still can't tell what you are trying to do.  what is the data supposed to look like?  can you type out some 2 - 3 samples rows with sample data?
0
 

Author Comment

by:sirnutty1
ID: 24378686
Hi Jonah11

Many thanks for your post.

I am in the process of building a student tracking application for a martial arts school. This report is specifically returning data with regards to monthly gradings (examinations) that the students do.

Eachd month a certain number of students are entered into the database as 'ready to grade'. These gradings normally occur over a four day period and on random weeks.

I have already generated a report that lists all students grading within a certain month which is displayed by day order. What i woud like to do is break the days of the month up. For example.

2009-05-13
Student 1
Student 6
Student 12

2009-05-15
Student 5
Student 3
Student 25

2009-05-17 etc..

To try and accomplish this I am trying to use a nested region.

I have created a recordset that returns a list of all students grading in a specified month, grouped by the day. The data returned gives me:

2009-05-13
2009-05-15
2009-05-17 etc...

Now I have the days that each grading is taking place, I need to  create a further recordset that uses the date values form the first recordset to return a list of student details. This list would then be nested beneath the values returned by the first recordset to produce the desired reult.

Thanks again for your help.
0
 
LVL 7

Accepted Solution

by:
Jonah11 earned 500 total points
ID: 24378845
for simplicity i am ignoring tables and just trying to get working output.  see if this works:
<?php do { ?>

	<b><?php echo $row_rsDateGroup['date']; ?></b><br />

	<?php do { ?>

		<?php echo $row_rsGradersTest['firstName']; ?> <?php echo $row_rsGradersTest['lastname']; ?><br />

		<?php } while ($row_rsGradersTest = mysql_fetch_assoc($rsGradersTest)); ?>

		<br/><br/>

<?php } while ($row_rsDateGroup = mysql_fetch_assoc($rsDateGroup)); ?>

Open in new window

0
 

Author Comment

by:sirnutty1
ID: 24389061
Many thanks Jonah11 and sorry for the delay. Will give this a try and get back to you.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Read about why website design really matters in today's demanding market.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now