Jump to content

noob help with WHILE function


superblunt

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/111824-noob-help-with-while-function/
Share on other sites

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>";

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>";

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.