newtoall Posted May 22, 2007 Share Posted May 22, 2007 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?? Quote Link to comment https://forums.phpfreaks.com/topic/52537-solved-a-puzzle/ Share on other sites More sharing options...
sasa Posted May 22, 2007 Share Posted May 22, 2007 use different variable name in 2nd for loop for($j = 0; $j<$shops; $j++) { echo '<option value = '.$shop[$j][0]; if ($shop[$j][0] == $shop[$i][0]) echo ' selected'; echo '>'.$shop[$j][0].'</option>\n'; } Quote Link to comment https://forums.phpfreaks.com/topic/52537-solved-a-puzzle/#findComment-259279 Share on other sites More sharing options...
newtoall Posted May 22, 2007 Author Share Posted May 22, 2007 sasa you are an absolute star, thank you so much it fixed it -- Nice one!!!! Quote Link to comment https://forums.phpfreaks.com/topic/52537-solved-a-puzzle/#findComment-259287 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.