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>"; ?> Link to comment https://forums.phpfreaks.com/topic/92031-i/ 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.. Link to comment https://forums.phpfreaks.com/topic/92031-i/#findComment-471322 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................. } Link to comment https://forums.phpfreaks.com/topic/92031-i/#findComment-471371 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.