Foreach数量和文章(从MySQL获取数据)
我有一个问题,显示每篇文章的数量,我通过一个从我从MySQL数据库获取数据的表单检查数据。Foreach数量和文章(从MySQL获取数据)
这里是我的代码:
<?php foreach ($results_articles as $input) : ?>
<input type="text" name="<?php echo $input->id_article; ?>_txtbox[]" style="text-align: center; width:30px;"></input>
<input
type="checkbox"
name="checked_articles[]"
value="<?php echo $input->id_article; ?>">
<?php echo "(".
($input->ref_article).")".
($input->nom_article)." (".
($input->prix_article)." €)"; ?><br>
<?php endforeach; ?>
因此, “checked_articles” 正确地出现在我的下一个页面上;但我真的不知道如何显示检查每篇文章的数量。
我想要你的帮助!
谢谢!如果您有其他信息,我会回复!
我相信“量”被放入文本input
,如果是的话,应该使用可访问:
foreach ($_POST['checked_articles'] as $checked_id)
{
$quantity = $_POST[$checked_id . '_txtbox'];
}
然而,由于txtbox
输入被命名为成为一个阵列,$quantity
将导致数组。也许这不是你想要的。然后,你可以这样做,而不是它:
<input type="text" name="txtbox[<?php echo $input->id_article; ?>]" style="text-align: center; width:30px;" />
有了这样的,该文本框将使用可访问:
$_POST['txtbox'][$checked_id];
谢谢你的回答! 但是,它似乎不显示它,因为我必须在表中显示它: http://jsfiddle.net/Lb7bP/ – AkdM 2013-03-01 16:58:55
编辑:对不起,我说得太快了,我忘了更改“ $ checked_id”。现在它显示数量,但仅限最后一个复选框。我该怎么做?此外,我已经有了这个“checked_articles”:http://jsfiddle.net/fdNE7/1/(它完美地工作) – AkdM 2013-03-01 17:19:02
您需要检索和存储'foreach'循环内的数量,就像在你的小提琴用'$ data_articles []',否则'$ quantity'将是最后一个选中的项目。 – Alasjo 2013-03-06 06:51:52
你是什么意思“每篇文章数量”?也许你的总检查文章计数? – Hast 2013-03-01 13:07:28
@ Hast:不,我的意思是我可以为每篇文章添加一个数字......这就是所谓的数量! ^^' – AkdM 2013-03-01 17:26:44