Php li标记中的内爆输入字段
我想使用内爆显示输入,如: 我的代码:Php li标记中的内爆输入字段,php,Php,我想使用内爆显示输入,如: 我的代码: $qty = array('2', '2', '1'); $price = array('200', '400', '1000'); $subtotal = array('400', '800', '1000'); echo "<li> Quantity: <input type='text' class='qty' name='qty' value='".implode("'> Quantity: <input type=
$qty = array('2', '2', '1');
$price = array('200', '400', '1000');
$subtotal = array('400', '800', '1000');
echo "<li>
Quantity: <input type='text' class='qty' name='qty' value='".implode("'>
Quantity: <input type='text' class='qty' name='qty' value='",$qty)."'>
Price: <input type='text' class='price' name='price' value='".implode("'>
Price: <input type='text' class='price' name='price' value='",$price)."'>
Subtotal: <input type='text' class='subtot' name='subtot' value='".implode("'>
Subtotal: <input type='text' class='subtot' name='subtot' value='",$subtotal)."'>
</li>";
$qty = array('2', '2', '1');
$price = array('200', '400', '1000');
$subtotal = array('400', '800', '1000');
foreach($qty as $key=>$value) {
echo "<li>
Quantity: <input type='text' class='qty' name='qty' value='".$qty[$key]."'>
Price: <input type='text' class='price' name='price' value='".$price[$key]."'>
Subtotal: <input type='text' class='subtot' name='subtot' value='".$subtotal[$key]."'>
</li>";
}
$qty=数组('2','2','1');
$price=数组('200','400','1000');
$subtotal=数组('400','800','1000');
回声“
数量:
数量:
价格:
价格:
小计:
小计:
”;
我的代码给出了以下结果:
编辑:
$qty = array('2', '2', '1');
$price = array('200', '400', '1000');
$subtotal = array('400', '800', '1000');
echo "<li>
Quantity: <input type='text' class='qty' name='qty' value='".implode("'>
Quantity: <input type='text' class='qty' name='qty' value='",$qty)."'>
Price: <input type='text' class='price' name='price' value='".implode("'>
Price: <input type='text' class='price' name='price' value='",$price)."'>
Subtotal: <input type='text' class='subtot' name='subtot' value='".implode("'>
Subtotal: <input type='text' class='subtot' name='subtot' value='",$subtotal)."'>
</li>";
$qty = array('2', '2', '1');
$price = array('200', '400', '1000');
$subtotal = array('400', '800', '1000');
foreach($qty as $key=>$value) {
echo "<li>
Quantity: <input type='text' class='qty' name='qty' value='".$qty[$key]."'>
Price: <input type='text' class='price' name='price' value='".$price[$key]."'>
Subtotal: <input type='text' class='subtot' name='subtot' value='".$subtotal[$key]."'>
</li>";
}
我希望我的代码的格式如下:
<li>
Quantity: <input ..>
Price: <input ..>
Subtotal: <input ..>
<li>
<li>
Quantity: <input ..>
Price: <input ..>
Subtotal: <input ..>
<li>
<li>
Quantity: <input ..>
Price: <input ..>
Subtotal: <input ..>
<li>
...
数量:
价格:
小计:
数量:
价格:
小计:
数量:
价格:
小计:
...
如果你用php($\u POST)提交它,它已经是一个数组(),你就不必再对它进行内爆了。如果你用php($\u POST)提交它,它已经是一个数组(),你就不必再对它进行内爆了。你需要添加一个循环来按如下顺序添加li元素。试试下面的方法。下面是使用相同长度的所有数组来实现的
$qty = array('2', '2', '1');
$price = array('200', '400', '1000');
$subtotal = array('400', '800', '1000');
for($i = 0; $i < count($qty); $i++) {
echo "<li>
Quantity: <input type='text' class='qty' name='qty' value='".$qty[$i]."'>
Price: <input type='text' class='price' name='price' value='".$price[$i]."'>
Subtotal: <input type='text' class='subtot' name='subtot' value='".$subtotal[$i]."'>
</li>";
}
$qty=数组('2','2','1');
$price=数组('200','400','1000');
$subtotal=数组('400','800','1000');
对于($i=0;$i<计数($qty);$i++){
回声“
数量:
价格:
小计:
”;
}
使用foreach示例更新:
$qty = array('2', '2', '1');
$price = array('200', '400', '1000');
$subtotal = array('400', '800', '1000');
echo "<li>
Quantity: <input type='text' class='qty' name='qty' value='".implode("'>
Quantity: <input type='text' class='qty' name='qty' value='",$qty)."'>
Price: <input type='text' class='price' name='price' value='".implode("'>
Price: <input type='text' class='price' name='price' value='",$price)."'>
Subtotal: <input type='text' class='subtot' name='subtot' value='".implode("'>
Subtotal: <input type='text' class='subtot' name='subtot' value='",$subtotal)."'>
</li>";
$qty = array('2', '2', '1');
$price = array('200', '400', '1000');
$subtotal = array('400', '800', '1000');
foreach($qty as $key=>$value) {
echo "<li>
Quantity: <input type='text' class='qty' name='qty' value='".$qty[$key]."'>
Price: <input type='text' class='price' name='price' value='".$price[$key]."'>
Subtotal: <input type='text' class='subtot' name='subtot' value='".$subtotal[$key]."'>
</li>";
}
$qty=数组('2','2','1');
$price=数组('200','400','1000');
$subtotal=数组('400','800','1000');
foreach($key=>$value的数量){
回声“
数量:
价格:
小计:
”;
}
您需要添加一个循环,以便按如下顺序添加li元素。试试下面的方法。下面是使用相同长度的所有数组来实现的
$qty = array('2', '2', '1');
$price = array('200', '400', '1000');
$subtotal = array('400', '800', '1000');
for($i = 0; $i < count($qty); $i++) {
echo "<li>
Quantity: <input type='text' class='qty' name='qty' value='".$qty[$i]."'>
Price: <input type='text' class='price' name='price' value='".$price[$i]."'>
Subtotal: <input type='text' class='subtot' name='subtot' value='".$subtotal[$i]."'>
</li>";
}
$qty=数组('2','2','1');
$price=数组('200','400','1000');
$subtotal=数组('400','800','1000');
对于($i=0;$i<计数($qty);$i++){
回声“
数量:
价格:
小计:
”;
}
使用foreach示例更新:
$qty = array('2', '2', '1');
$price = array('200', '400', '1000');
$subtotal = array('400', '800', '1000');
echo "<li>
Quantity: <input type='text' class='qty' name='qty' value='".implode("'>
Quantity: <input type='text' class='qty' name='qty' value='",$qty)."'>
Price: <input type='text' class='price' name='price' value='".implode("'>
Price: <input type='text' class='price' name='price' value='",$price)."'>
Subtotal: <input type='text' class='subtot' name='subtot' value='".implode("'>
Subtotal: <input type='text' class='subtot' name='subtot' value='",$subtotal)."'>
</li>";
$qty = array('2', '2', '1');
$price = array('200', '400', '1000');
$subtotal = array('400', '800', '1000');
foreach($qty as $key=>$value) {
echo "<li>
Quantity: <input type='text' class='qty' name='qty' value='".$qty[$key]."'>
Price: <input type='text' class='price' name='price' value='".$price[$key]."'>
Subtotal: <input type='text' class='subtot' name='subtot' value='".$subtotal[$key]."'>
</li>";
}
$qty=数组('2','2','1');
$price=数组('200','400','1000');
$subtotal=数组('400','800','1000');
foreach($key=>$value的数量){
回声“
数量:
价格:
小计:
”;
}
我们开始吧,这是一项非常简单的工作,您只需遍历任何数组,然后在一次迭代中打印/回显整个li,包括数量、价格、小计
新脚本
<?php
$qty = array('2', '2', '1');
$price = array('200', '400', '1000');
$subtotal = array('400', '800', '1000');
for($i = 0; $i < count($qty); $i++){?>
<li>
Quantity: <input type='text' class='qty' name='qty' value='<?php echo $qty[$i];?>'/>
Price: <input type='text' class='price' name='price' value='<?php echo $price[$i];?>'/>
Subtotal: <input type='text' class='subtot' name='subtot' value='<?php echo $subtotal[$i];?>'/>
</li>
<?php }?>
数量:
使用foreach的脚本
<?php
$qty = array('2', '2', '1');
$price = array('200', '400', '1000');
$subtotal = array('400', '800', '1000');
foreach($qty as $key => $value){?>
<li>
Quantity: <input type='text' class='qty' name='qty' value='<?php echo $qty[$key];?>'/>
Price: <input type='text' class='price' name='price' value='<?php echo $price[$key];?>'/>
Subtotal: <input type='text' class='subtot' name='subtot' value='<?php echo $subtotal[$key];?>'/>
</li>
<?php }?>
数量:
我们开始吧,这是一项非常简单的工作,您只需遍历任何数组,然后在一次迭代中打印/回显整个li,包括数量、价格、小计
新脚本
<?php
$qty = array('2', '2', '1');
$price = array('200', '400', '1000');
$subtotal = array('400', '800', '1000');
for($i = 0; $i < count($qty); $i++){?>
<li>
Quantity: <input type='text' class='qty' name='qty' value='<?php echo $qty[$i];?>'/>
Price: <input type='text' class='price' name='price' value='<?php echo $price[$i];?>'/>
Subtotal: <input type='text' class='subtot' name='subtot' value='<?php echo $subtotal[$i];?>'/>
</li>
<?php }?>
数量:
使用foreach的脚本
<?php
$qty = array('2', '2', '1');
$price = array('200', '400', '1000');
$subtotal = array('400', '800', '1000');
foreach($qty as $key => $value){?>
<li>
Quantity: <input type='text' class='qty' name='qty' value='<?php echo $qty[$key];?>'/>
Price: <input type='text' class='price' name='price' value='<?php echo $price[$key];?>'/>
Subtotal: <input type='text' class='subtot' name='subtot' value='<?php echo $subtotal[$key];?>'/>
</li>
<?php }?>
数量:
请检查。“用于内装函数的数组在哪里?@dinespatra代码已更新。如果要显示,请分解数组,然后将其值赋给您的echo。@FrayneKonok是否可以使用我的代码进行示例?等等.”。。我在为你做……请查收。“用于内装函数的数组在哪里?@dinespatra代码已更新。如果要显示,请分解数组,然后将其值赋给您的echo。@FrayneKonok是否可以使用我的代码进行示例?等等.”。。我正在为您执行..$SESSION Not submit。您是指explode()
吗?我可以告诉您,您正在尝试分配您拥有的数组值吗?如果我错了,请纠正我$SESSION Not submit。您是指explode()
,我可以告诉您,您是在尝试分配您拥有的数组值吗?如果我错了,请纠正我。我有什么想法吗?当然有。在这种情况下,您只需要使用foreach索引。我将更新我的代码。@VintageBeef要求人们将解决方案更改为使用foreach
而不是for
尖叫。请不要这样做。谢谢。有什么好主意吗?当然有。在这种情况下,您只需要使用foreach索引。我将更新我的代码。@VintageBeef要求人们将解决方案更改为使用foreach
而不是for
尖叫。请不要这样做。谢谢