Jump to content

$i++??


forumnz

Recommended Posts

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

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

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.