Hello forum,
I've got a quick question here about displaying array elements in text
boxes. When I echo each element of this array as normal HTML, it displays
fine.
$aryNames = array();
$aryNames[0]= "George Bernard Shaw";
$aryNames[1]= "Julia Roberts";
$aryNames[2]= "Homer Simpson";
When I try to write the array elements to text boxes, only the first name of
each full name displays. What's going on?
You can view the results at http://braindivot.com/mlm/array_in_textbox.php
<http://braindivot.com/mlm/array_in_textbox.php>; .
The code's below.
Thanks,
Samtediou
<?php
$aryNames = array();
$aryNames[0]= "George Bernard Shaw";
$aryNames[1]= "Julia Roberts";
$aryNames[2]= "Homer Simpson";
//Write names array in tabular form
echo "<h2>Array elements displayed as a normal HTML table</h2><br>";
echo "<table border=1>";
for ($i=0; $i < sizeof($aryNames); $i++){
$num = $i + 1;
echo "<tr><td>$num</td>";
echo "<td>$aryNames[$i]</td></tr>";
}
echo "</table><br><br>";
//Write names array in text boxes
echo "<h2>Array elements displayed in text boxes </h2><br>";
echo "<table border=1>";
for ($i=0; $i < sizeof($aryNames); $i++){
$num = $i + 1;
$txt_name = "txtName" . $num;
echo "<tr><td>$num</td>";
echo "<td><input type=text name=$txt_name
value=$aryNames[$i]</td></tr>";
}
echo "</table>";
?>