如何将数据存储到MySQL以进行数组输入
希望我的问题对帖子来说是正确的。
<form action="process.php?id=<?php echo intval($order['id']);?>" method="post">
<ul>
<?php
$sd = 'SELECT * FROM download WHERE pid IN ('.$order['pid'].') ORDER BY pid ASC'; // pid IN (3,4,5)
$qd = $db->rq($sd);
$no = 1; while($download = $db->fetch($qd)) {
?>
<li>
<?php echo $no; ?> <?php echo $download['title']; ?>
<input type="hidden" name="mid[]" value="<?php echo $order['mid']; ?>" />
<input type="hidden" name="pid[]" value="<?php echo $download['pid']; ?>" />
</li>
<?php $no++; } ?>
</ul>
<input type="submit" name="submit" value="Submit" />
</form>
输出
- 索尼爱立信驱动程序
- 索尼爱立信应用程序
- 三星驱动
- 程序摩托罗拉驱动程序
问题
- 如何将数据
输出
存储到下面的表结构中>process.php
数据将被保存为类似这样的内容。
<前><代码>id |中| PID |标题 ---------------------------------------------------- 1 | 1 | 3 |索尼爱立信驱动程序 ---------------------------------------------------- 2 | 1 | 3 |索尼爱立信应用程序 ---------------------------------------------------- 3 | 1 | 4 |三星驱动程序 ---------------------------------------------------- 4 | 1 | 5 |摩托罗拉驱动程序 ----------------------------------------------------
process.php
if (isset($_POST['submit']) && !empty($_POST['submit'])) {
// I'm blur how to get dynamic mid[] & pid[] here
}
Hope my question is correct to the post.
<form action="process.php?id=<?php echo intval($order['id']);?>" method="post">
<ul>
<?php
$sd = 'SELECT * FROM download WHERE pid IN ('.$order['pid'].') ORDER BY pid ASC'; // pid IN (3,4,5)
$qd = $db->rq($sd);
$no = 1; while($download = $db->fetch($qd)) {
?>
<li>
<?php echo $no; ?> <?php echo $download['title']; ?>
<input type="hidden" name="mid[]" value="<?php echo $order['mid']; ?>" />
<input type="hidden" name="pid[]" value="<?php echo $download['pid']; ?>" />
</li>
<?php $no++; } ?>
</ul>
<input type="submit" name="submit" value="Submit" />
</form>
Output
- Sony Ericsson Drivers
- Sony Ericsson Apps
- Samsung Drivers
- Motorola Drivers
Question
- How to store (save) the data
Output
to table structure at below onprocess.php
Data will be save something like these.
id | mid | pid | title ----------------------------------------- 1 | 1 | 3 | Sony Erricson Drivers ----------------------------------------- 2 | 1 | 3 | Sony Erricson Apps ----------------------------------------- 3 | 1 | 4 | Samsung Drivers ----------------------------------------- 4 | 1 | 5 | Motorola Drivers -----------------------------------------
process.php
if (isset($_POST['submit']) && !empty($_POST['submit'])) {
// I'm blur how to get dynamic mid[] & pid[] here
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为标题创建第三个隐藏字段,例如:
现在您可以像这样存储它,假设您的页面被提交到
process.php
,这就是您应该放在那里的内容:Create a third hidden field for titles eg:
Now you can store it like this, suppose your page gets submitted to
process.php
, this is what you should put in there:您可以简单地对 $_POST['mid'] 和 $_POST['pid'] 数组进行循环,如下所示:
如果您也想传递项目的名称,则可以像发送 'mid' 一样传递它' 和 'pid' 字段。
You can simply do a loop over the $_POST['mid'] and the $_POST['pid'] array, like this:
If you want to pass the item's name too you can just pass it the same way you sent 'mid' and 'pid' fields.
您可以通过访问
POST< 以与检查
submit
相同的方式获取mid[]
和pid[]
的值/code> 变量:由于它们作为数组发布,因此它们将是
$_POST
变量中的数组。您还可以通过以下方式检查单个 $_POST 变量或整个 $_POST 变量的结构:对于调试或找出您不确定其内容的变量,这是一个有用的函数。
You get the values for
mid[]
andpid[]
the same way you're checkingsubmit
, by accessing thePOST
variables:Since they're posted as arrays, they'll be arrays in the
$_POST
variable. You can also check the structure of the individual $_POST variables or the entire $_POST variable by the following:This is a useful function for debugging or figuring out a variable whose contents you're unsure about.