superblunt Posted June 25, 2008 Share Posted June 25, 2008 I want to use 2 WHILE functions but it only displays the first one <form name="mainitem" action="../aea/result/mainitem.php" method="POST"> Select Supplier<select name="mainitem"> <?php while ($row2 = mysql_fetch_array($getmainitem)) {?> <option value=" <?php echo $row2['id']; ?> "> <?php echo $row2['mainitem'];} ?> </option>></select><BR> <input type="submit"/> </form><BR><BR> <?php echo "<table border='1'> <tr> <th>Itemname</th> <th>TotalStock</th> <th>Totalmass</th> <th>Totalprice</th> </tr>"; while($row3 = mysql_fetch_array($getmainitem)) { echo "<tr>"; echo "<td>" . $row3['itemname'] . "</td>"; echo "<td>" . $row3['totalstock'] . "</td>"; echo "<td>" . $row3['totalmass'] . "</td>"; echo "<td>" . $row3['totalprice'] . "</td>"; echo "</tr>"; } echo "</table>"; Is there a way to stop the function so i can do it again Quote Link to comment https://forums.phpfreaks.com/topic/111824-noob-help-with-while-function/ Share on other sites More sharing options...
blueman378 Posted June 25, 2008 Share Posted June 25, 2008 please put inside code tags, <form name="mainitem" action="../aea/result/mainitem.php" method="POST"> Select Supplier<select name="mainitem"> <?php while ($row2 = mysql_fetch_array($getmainitem)) {?> <option value=" <?php echo $row2['id']; ?> "> <?php echo $row2['mainitem'];} ?> </option>></select><BR> <input type="submit"/> </form><BR><BR> <?php echo "<table border='1'> <tr> <th>Itemname</th> <th>TotalStock</th> <th>Totalmass</th> <th>Totalprice</th> </tr>"; while($row3 = mysql_fetch_array($getmainitem)) { echo "<tr>"; echo "<td>" . $row3['itemname'] . "</td>"; echo "<td>" . $row3['totalstock'] . "</td>"; echo "<td>" . $row3['totalmass'] . "</td>"; echo "<td>" . $row3['totalprice'] . "</td>"; echo "</tr>"; } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/111824-noob-help-with-while-function/#findComment-574021 Share on other sites More sharing options...
blueman378 Posted June 25, 2008 Share Posted June 25, 2008 but what do you mean stop it so you can do it again? Quote Link to comment https://forums.phpfreaks.com/topic/111824-noob-help-with-while-function/#findComment-574023 Share on other sites More sharing options...
sasa Posted June 25, 2008 Share Posted June 25, 2008 try <form name="mainitem" action="../aea/result/mainitem.php" method="POST"> Select Supplier<select name="mainitem"> <?php while ($row2 = mysql_fetch_array($getmainitem)) {?> <option value=" <?php echo $row2['id']; ?> "> <?php echo $row2['mainitem'];} ?> </option>></select><BR> <input type="submit"/> </form><BR><BR> <?php echo "<table border='1'> <tr> <th>Itemname</th> <th>TotalStock</th> <th>Totalmass</th> <th>Totalprice</th> </tr>"; mysql_data_seek($getmainitem,0); while($row3 = mysql_fetch_array($getmainitem)) { echo "<tr>"; echo "<td>" . $row3['itemname'] . "</td>"; echo "<td>" . $row3['totalstock'] . "</td>"; echo "<td>" . $row3['totalmass'] . "</td>"; echo "<td>" . $row3['totalprice'] . "</td>"; echo "</tr>"; } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/111824-noob-help-with-while-function/#findComment-574025 Share on other sites More sharing options...
kenrbnsn Posted June 25, 2008 Share Posted June 25, 2008 Do the while statement first, storing the results for each type of HTML you want to produce: <?php $tmp1 = array(); $tmp2 = array(); while ($rw = mysql_fetch_array($getmainitem)) { $tmp1[] = '<option value="' . $rw['id'] . '">' . $rw['mainitem]' . '</option>'; $tmp = array(); $tmp[] = "<tr>"; $tmp[] = "<td>" . $rw['itemname'] . "</td>"; $tmp[] = "<td>" . $rw['totalstock'] . "</td>"; $tmp[] = "<td>" . $rw['totalmass'] . "</td>"; $tmp[] = "<td>" . $rw['totalprice'] . "</td>"; $tmp[] = "</tr>"; $tmp2[] = implode("\n",$tmp); }?> <form name="mainitem" action="../aea/result/mainitem.php" method="POST"> Select Supplier<select name="mainitem"> <?php echo implode("\n",$tmp1) . "\n"; ?> </select> <input type="submit" name="submit" /> <?php echo "<table border='1'> <tr> <th>Itemname</th> <th>TotalStock</th> <th>Totalmass</th> <th>Totalprice</th> </tr>"; echo implode("\n",$tmp2) . "\n"; echo '</table>'; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/111824-noob-help-with-while-function/#findComment-574108 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.