Odd for loop behavior.

From: Date: Mon, 20 Jan 2003 18:48:44 +0000
Subject: Odd for loop behavior.
Groups: php.windows 
Request: Send a blank email to php-windows+get-17995@lists.php.net to get a copy of this message
I have the following code: for($x = 0; $x < sizeof($traits); $x++) { echo '<tr>' . '<td align="right" class="header">' . $traits[$x]['traitname'] . $x . '</td>' . '<td align="center" class="text"><input type="radio" name="' . $traits[$x]['traitid'] . '" value="1"> 1</td>' . '<td align="center" class="text"><input type="radio" name="' . $traits[$x]['traitid'] . '" value="2"> 2</td>' . '<td align="center" class="text"><input type="radio" name="' . $traits[$x]['traitid'] . '" value="3"> 3</td>' . '<td align="center" class="text"><input type="radio" name="' . $traits[$x]['traitid'] . '" value="4"> 4</td>' . '</tr>'; } The array this code is using looks like this: Array ( [0] => Array ( [traitid] => 1 [traitname] => Ideas ) [1] => Array ( [traitid] => 3 [traitname] => Voice ) [2] => Array ( [traitid] => 5 [traitname] => Fluency ) ) Here is the HTML: <tr> <td align="right" class="header">Ideas0</td> <td align="center" class="text"> <input type="radio" name="1" value="1"> 1 </td> <td align="center" class="text"> <input type="radio" name="1" value="2"> 2 </td> <td align="center" class="text"> <input type="radio" name="1" value="3"> 3 </td> <td align="center" class="text"> <input type="radio" name="1" value="4"> 4 </td> </tr> <tr> <td align="right" class="header">1</td> <td align="center" class="text"> <input type="radio" name="" value="1"> 1 </td> <td align="center" class="text"> <input type="radio" name="" value="2"> 2 </td> <td align="center" class="text"> <input type="radio" name="" value="3"> 3 </td> <td align="center" class="text"> <input type="radio" name="" value="4"> 4 </td> </tr> <tr> <td align="right" class="header">Voice2</td> <td align="center" class="text"> <input type="radio" name="3" value="1"> 1 </td> <td align="center" class="text"> <input type="radio" name="3" value="2"> 2 </td> <td align="center" class="text"> <input type="radio" name="3" value="3"> 3 </td> <td align="center" class="text"> <input type="radio" name="3" value="4"> 4 </td> </tr> <tr> <td colspan="5"> <input type="submit" value="Submit" class="formfield"> <input type="reset" value="Cancel" class="formfield"> </td> </tr> As you can see, where value [1] of the arrray is supposed to be it is inserting nothing. But for value [2] it is inserting [1]'s data. I'm hoping someone can take a look at this and point out where I may have gone wrong. The really odd thing is this code seems to work with different data. For example, if I have a 6 field array it properly inserts [0] to [5]. Thanks for any input. ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^ Sterling Anderson -- sterling@sterlinganderson.net http://sterlinganderson.net Human female: "The sheer drama of this election has driven voter turnout to it's highest level in centuries, six percent." Morbo: "Exit poll show evil underdog Richard Nixon trailing with estimated zero votes." Human female: "The time is 7:59 and the robot polls are now opening. And robot votes are now in. Nixon has won." Morbo: "Morbo congratulates our gargantuan cyborg president. May death come quickly to his enemies." ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^

« previous php.windows (#17995) next »