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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.