Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PHP - Repeat Region question

New Here ,
Dec 22, 2009 Dec 22, 2009

I have a table with a repeat region that has 2 record set.  The first is the list of the data and just one of the fields uses another table to count the record_id.  I nested the region and first set of records show the count and it does change if the other field is added so I know the first one is working but all other regions (other than the first one) have that field as blank.

Here is the code:

<?php do { ?>

<table wideth = "620" border = "1" id="tablen">

<tr>

<th width="54">Date</th>

<th width="60">Day</th>

<th width="60">Time</th>

<th width="148">Course</th>

<th width="56">Cost</th>

<th width="56">Signed Up</th>

<th width="51">Field</th>

<th width="93">Register</th>

</tr>

<tr>

<td><?php echo $row_getEven['even_date'];?></td>

<td><?php echo $row_getEven['round_day'];?></td>

<td><?php echo $row_getEven['time'];?></td>

<td><?php echo $row_getEven['course'];?></td>

<td><?php echo $row_getEven['player_cost'];?></td>

<? do { ?>

<td><?php echo $row_getCountp['count_even'];?></td>

<?php } while ($row_getCountp = mysql_fetch_assoc($getCountp));?>

<td><?php echo $row_getEven['register'];?></td>

</tr>

</table>

</form>

</p>

<p><img src="Images/each.jpg" width="620" height="10" /></p>

<?php } while ($row_getEven = mysql_fetch_assoc($getEven));?>

Any ideas?

TOPICS
Server side applications
448
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 23, 2009 Dec 23, 2009

The explanation of what you're trying to do is not at all clear. However, the code you have posted here will produce a mess.

Basically, a repeat region is a do... while loop. What it does is loop through the database results until they have all been used. Consequently, nesting two loops, as you have done, will produce the following effect:

  • The first time through the getEven recordset, the table headers and the first five fields will be displayed.
  • Then the getCountp recordset kicks in, and creates a table cell in the second row for every result in the recordset. If there are 10 results, it will add 10 cells after the first five.
  • After the getCountp repeat region has finished, the final field in the second row is populated, the table and form are closed, and an image is displayed.
  • The getEven recordset then goes into the second iteration of the loop, displaying the table headers again, plus the first five fields in the second row.
  • When it gets to the getCountp repeat region, there's nothing left in the getCountp recordset to display because you already looped through it the first time. So it's ignored.
  • The final field in the second row is displayed, but the row will be one cell short, because the getCountp field had nothing to display.
  • The getEven recordset will continue the same way until it reaches the end.

If you want to display a value in each row, you will need to create a SQL query that joins the two tables, and use a single repeat region to loop through the results.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 23, 2009 Dec 23, 2009
LATEST

Ok, I understand the problem but I don't know how to create the recordset as I need.  Let me explain.

I have a table in the database that lists courses and has ID's and whether they are active or not.  I want the table to list all active (that equal 'yes') courses.  Then I have another table that is called players that allows players to register for the course.  I want the table to pull the count of players for each course from the players table to display on each row of each course to show how many registered for each.  The course table has a game_id and so does the players table which tells me what course(s) they registered for.  I tried to join the tables but kept getting errors.  Any help would be appreciated.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines