Link to home
Start Free TrialLog in
Avatar of cataleptic_state
cataleptic_stateFlag for United Kingdom of Great Britain and Northern Ireland

asked on

nesting do while loops php/mysql

Hi,
I have a page that I want to show archive documents I want it so that I have dates in asending order and underneath the date I want the documents to be listed

so the page will have

2009
 1) document 1
 2) document 2

2008
 1) document 1
 2) document 2


 This is what I have at the moment. Dreamweaver wont allow me to nest the while loop

Is there an easier way of doing it?
 
mysql_select_db($database_db, $db);
$query_enable_login = "SELECT disable_login FROM season";
$enable_login = mysql_query($query_enable_login, $db) or die(mysql_error());
$row_enable_login = mysql_fetch_assoc($enable_login);
$totalRows_enable_login = mysql_num_rows($enable_login);

mysql_select_db($database_db, $db);
$query_archives = "SELECT `year` FROM archive ORDER BY `year` ASC";
$archives = mysql_query($query_archives, $db) or die(mysql_error());
$row_archives = mysql_fetch_assoc($archives);
$totalRows_archives = mysql_num_rows($archives);

  <h2><?php echo $row_archives['year']; ?></h2>
        <?php do { ?>
          <hr />
            <a href="archives/<?php echo $row_archive_item['file']; ?>"><?php echo $row_archive_item['archive_title']; ?></a>
            <hr />
          <?php } while ($row_archive_item = mysql_fetch_assoc($archive_item)); ?>
        </p>

Open in new window

Avatar of honestman31
honestman31

is that ok to go with the for loop ? or foreach  loop ?
Avatar of Jason C. Levine
Hi cataleptic_state,

There is an easier way to do the loop using this behavior:

http://www.tom-muck.com/extensions/help/simulatednestedregion/

1. Download and install it

2. Create your repeat region so that everything is inside the loop:


        <?php do { ?>
<h2><?php echo $row_archives['year']; ?></h2>
          <hr />
            <a href="archives/<?php echo $row_archive_item['file']; ?>"><?php echo $row_archive_item['archive_title']; ?></a>
            <hr />
          <?php } while ($row_archive_item = mysql_fetch_assoc($archive_item)); ?>
     
3. Highlight the element that should only repeat once:

<h2><?php echo $row_archives['year']; ?></h2>

4. Apply the Simulated Nested Repeat Region from the Server Behaviors Panel

5. Drink Beer.

Looks to me like you're trying to use "$row_archive_item[]" before you have fetched it with "$row_archive_item = mysql_fetch_assoc($archive_item)".  In addition, "$archive_item" is not defined anywhere.
Avatar of cataleptic_state

ASKER

Hi DaveBaldwin,
The archive_items is another recordset, it is there, just forgot to add it to EE code window.

I will give those examples a try thank you all.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial