Forum Moderators: coopster

Message Too Old, No Replies

Issues with nested while loops/if statement

Single execution of if but full execution of loop?

         

PSWorx

12:11 am on May 13, 2006 (gmt 0)

10+ Year Member



Ok i re-wrote this loop three times, the idea is to get the page id then cross check that with a link id for a match to determine the number of linked pages

It uses two while loops nested in side each other and also an if statement within the final while:

$pagesQuery=mysql_query("SELECT * FROM ******* ORDER BY ******** ASC");
$_SERVER['totalPagesNum']=mysql_num_rows($pagesQuery);
$linksQuery=mysql_query("SELECT * FROM ******* ORDER BY ******** ASC");

$_SERVER['linkedPagesTotal']=0;
$_SERVER['disabledPagesTotal']=0;

while($pagesData=mysql_fetch_array($pagesQuery)){
if($pagesData['page_disabled']==1){
$_SERVER['disabledPagesTotal']++;
}
while($linksData=mysql_fetch_array($linksQuery)){
if($pagesData['page_link_id']==$linksData['site_links_url']){
$_SERVER['linkedPagesTotal']++;
break; //Just added this in now allows for 3 executions max?

}
}
}

The issue is the if statement only gets executed once however the while does itterate through each of the links.

Ive a seperate query for each while loop.

Any ideas whats going wrong, its one of those W*F why wont it work moments after lots of good progress.

Is the mysql_num_rows function cuasing a prob?

TIA

PSWorx

12:35 am on May 13, 2006 (gmt 0)

10+ Year Member



Problem solved,

Sat the secondary while loop inside a function and called that inside the main loop which succesfully itterated each time and produced the results correctly.

(sorry about the typos)