Tuesday, 15 March 2011

php - Only loop part of result -



php - Only loop part of result -

i'm new php/sql , i'm aware maybe basic question cannot find answer. returning array of results next query however, want part of returned info loop:

<?php $result = mysqli_query($con," select lastname slast, firstname sfirst, b.date ddate, b.name dname, a.wk1places ewk1 students left bring together (select id, name, wk1places employers) on a.id = $e_id left bring together (select id, date, name dates) b on b.id = 1 wk1 = a.name"); $wk1 = mysqli_num_rows($result); while($row = mysqli_fetch_array($result)) { ?> <div style="float:left"> week <?php echo $row['dname'] ;?><br> <?php echo $row['ddate'] ;?> <!-- info loop --> <p> <?php echo $row['slast'] ;?>, <?php echo $row['sfirst'] ;?> </p> <!-- / --> <?php echo $wk1 ?> / <?php echo $row['ewk1'] ;?> <?php }?>

the code enclosed in <p> should loop, echoed rows above , below should remain same , not duplicated. help much appreciated!! :)

if utilize do while loop after doing first read of results outside loop, can capture 2 repeated fields first read , loop on info selecting wish use.

as while test done @ end of loop , not origin first row gets processed part of read of result outside loop, , 2 fields interested in in loop used in code within loop.

$wk1 = mysqli_num_rows($result); if ( $wk1 > 0 ) : $row = mysqli_fetch_array($result); $ewk1 = $row['ewk1']; echo '<div style="float:left">week '; echo $row['dname'] . '<br>' . $row['ddate']; { echo '<p>' . $row['slast'] . ', ' . $row['sfirst'] . '</p>'; } while ($row = mysqli_fetch_array($result)); echo $wk1 . ' / ' . $ewk1; endif; ?>

php sql loops select

No comments:

Post a Comment