Jump to content

[SOLVED] A puzzle??


newtoall

Recommended Posts

Hi I have posted this before but I thought I would add a proper example.

 

The following is an example of a form used to display an array which works fine:

 

<?php

$shop = array( array("rose", 1.25 , 15),
               array("daisy", 0.75 , 25),
               array("orchid", 1.15 , 7) 
             ); 
$shops = sizeof($shop);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="update.php">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">


<tr>
<td align="center"><strong>select</strong></td>
<td align="center"><strong>flower</strong></td>
<td align="center"><strong>price</strong></td>
<td align="center"><strong>number</strong></td>
</tr>
<?php
for($i = 0; $i<$shops; $i++){
?>
<tr>
<td align="center"><input name="name[]" type="text" id="name"
value="<?php echo $shop[$i][0]?>" ></td>
<td align="center"><input name="lastname[]" type="text" id="age"
value="<?php echo $shop[$i][1]?>"></td>
<td align="center"><input name="email[]" type="text" id="wife"
value="<?php echo $shop[$i][2]?>"></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</form>
</table>

 

However If I try to add a select to this table the 3 rows displayed above no longer show instead I get just 1 row:

<?php

$shop = array( array("rose", 1.25 , 15),
               array("daisy", 0.75 , 25),
               array("orchid", 1.15 , 7) 
             ); 
$shops = sizeof($shop);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="update.php">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">


<tr>
<td align="center"><strong>select</strong></td>
<td align="center"><strong>flower</strong></td>
<td align="center"><strong>price</strong></td>
<td align="center"><strong>number</strong></td>
</tr>
<?php
for($i = 0; $i<$shops; $i++){
?>
<tr>
<td><select name = "PCode[]"> <?php

      for($i = 0; $i<$shops; $i++)
      {
        echo '<option value = '.$shop[$i][0];
        if ($shop[$i][0] == $shop[$i][0]) echo ' selected';
        echo '>'.$shop[$i][0].'</option>\n';
      }

?></select></td>
<td align="center"><input name="name[]" type="text" id="name"
value="<?php echo $shop[$i][0]?>" ></td>
<td align="center"><input name="lastname[]" type="text" id="age"
value="<?php echo $shop[$i][1]?>"></td>
<td align="center"><input name="email[]" type="text" id="wife"
value="<?php echo $shop[$i][2]?>"></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</form>
</table>


 

can anyone advise on how I can get all 3 rows to display with the select in each one??

 

Link to comment
https://forums.phpfreaks.com/topic/52537-solved-a-puzzle/
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.