2012-05-30 18:04 浏览 58


i have a problem to create a dynamic form, here is my array

$myThemeConfig = array (
'slid_img' => 
  array (
'img_1' => 'im1.jpg',
'img_2' => 'im2.jpg',
'img_3' => 'im3.jpg',
'img_4' => 'im4.jpg',
'img_5' => 'im5.jpg',
'img_6' => 'im6.jpg',
'img_7' => NULL,
'img_8' => NULL,
'img_9' => NULL,
'img_10' => NULL,
'slid_til' => 
array (
'title_1' => 'title1 is your title 1',
'title_2' => 'title2 is your title 2',,
'title_3' => 'title3 is your title 3',
'title_4' => 'title4 is your title 4',
'title_5' => 'title5 is your title 5',
'title_6' => 'title6 is your title 6',
'title_7' => NULL,
'title_8' => NULL,
'title_9' => NULL,
'title_10' => NULL,

and i want to display at html

 <tbody id="copyf">
<td>Slider Image 1</td>
<td><div><input type="text" value="im1.jpg" name="img_1"></div></td></tr>
<td>Slider Title 1></td><td><div><textarea name="title_1">title1 is your title 1</textarea></div></td></tr></tbody>

   <tbody id="copyf">
   <td>Slider Image 2</td>
   <td><div><input type="text" value="im2.jpg" name="img_2"></div></td></tr>
<td>Slider Title 2 ></td><td><div><textarea name="title_2">title2 is your title 2</textarea></div></td></tr></tbody>

 <tbody id="copyf">
<td>Slider Image 3</td>
<td><div><input type="text" value="im3.jpg" name="img_3"></div></td></tr>
<td>Slider Title 3 ></td><td><div><textarea name="title_3">title3 is your title 3</textarea></div></td></tr></tbody>

and so on..

Im try to use foreach loop but it's only loops one array,

here the code i working for.


its almost make me desperate since i'm not expert ini php code..

please.. please please.. :)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答 默认 最新

  • 已采纳
    dongzhan9100 dongzhan9100 2012-05-30 18:08
    $c = count ($myThemeConfig ['slid_img']);
    for ($i=1; $i<=$c; $i++) : ?>
        <tbody id="copyf">
                    Slider Image <?php echo $i; ?>
                        <input type="text" value="<?php echo $myThemeConfig['slid_img'] ['img_' . $i]; ?>" name="img_<?php echo $i; ?>" />
                    Slider Title <?php echo $i; ?> >
                        <textarea name="title_<?php echo $i; ?>"><?php echo $myThemeConfig['slid_til'] ['title_' . $i]; ?></textarea>
    <?php endfor; ?>
    点赞 评论 复制链接分享