forumnz Posted February 20, 2008 Share Posted February 20, 2008 Why wont this work? It always displays item0 when it should display that only once, then item1 etc.. Code snippet: <?php while($row = mysql_fetch_array($result)) { $name = $row['name']; $id = $row['id']; $price = $row['price']; $i=0; echo "<div id=\"sec\"> <label><div id=\"text\">Name:</div> <input class=\"wid required\" name=\"item$i\" type=\"text\" value=\"$name\" /> </label> </div>"; $i++; echo "<br /><br /><div style=\"clear:both; margin-bottom:5px; margin-top:5px; border-bottom:1px dashed #999999;\"></div>"; } echo "</div>"; ?> Quote Link to comment Share on other sites More sharing options...
dotBz Posted February 20, 2008 Share Posted February 20, 2008 You always declare $i = 0. Put it before the loop.. Quote Link to comment Share on other sites More sharing options...
cyrixware Posted February 20, 2008 Share Posted February 20, 2008 Why wont this work? It always displays item0 when it should display that only once, then item1 etc.. Code snippet: <?php while($row = mysql_fetch_array($result)) { $name = $row['name']; $id = $row['id']; $price = $row['price']; $i=0; echo "<div id=\"sec\"> <label><div id=\"text\">Name:</div> <input class=\"wid required\" name=\"item$i\" type=\"text\" value=\"$name\" /> </label> </div>"; $i++; echo "<br /><br /><div style=\"clear:both; margin-bottom:5px; margin-top:5px; border-bottom:1px dashed #999999;\"></div>"; } echo "</div>"; ?> create a loop in order to increment by 1. ex. $i = 0; while($i...condition){ $i++; block of statements................. } Quote Link to comment 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.