Dean List Principal Edit Principal Principal: Create Faculty-6ren">
gpt4 book ai didi

PHP HTML 形式多维数组 MySQL

转载 作者:行者123 更新时间:2023-11-29 12:34:17 25 4
gpt4 key购买 nike

我有带有代码的 php 页面:一切正常。

<?php
session_start();
include 'db.php';//database connection

if ( isset($_POST['permission']))
{
$x=$_POST['permission'];
$a=print_r($x);//print array structure

$permit_group=array('Dean','Principal');//redefine of permission array as already
//defined in form permission[Dean][] etc.

$permit_no=count($permit_group);//count array size of all defined areas
$b=print_r($permit_no);//its out put is 2; i am looking for: $permit_no=count($x)???

for($i=0; $i<$permit_no; $i++)//for loop for all possible permission (Dean, Principal
etc.)
{

$jj=count($permit_group['$i']);//count size of subarea given to to individual area
//person and output is 0; i am looking for: $jj=count($x['area'])???
$c=print_r($jj);

for($j=0; $j<jj; $j++)
{
$x1=$permit_group[$i];//i am looking for this:$x1=$x[$i]; How can i do this ?
$x2=$x[$permit_group[$i]][$j];//i am looking for this:$x2=$x[$i][$j];How can i do this?
mysqli_query($connection,"INSERT INTO upermission (area, subarea) VALUES
('$x1','$x2')");
}
}
}
?>
<div>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div>
<ul>Dean
<li><input type="checkbox" name="permission[Dean][]" value="list"/><label>List
Principal
</label></li>
<li><input type="checkbox" name="permission[Dean][]" value="Edit"/><label>Edit
Principal
</label></li>
</ul>

<ul>Principal:
<li><input type="checkbox" name="permission[Principal][]" value="create"/>
<label>Create Faculty</label></li>
<li><input type="checkbox" name="permission[Principal][]" value="edit"/><label>Edit
Faculty</label></li>
<li><input type="checkbox" name="permission[Principal][]" value="add"/>
<label>Add Faculty</label></li>
<li><input type="checkbox" name="permission[Principal][]" value="delete"/>
<label>Delete Faculty</label></li>
</ul>
</div>
<input type="submit" name="submit" />
</form>
</div>

我的问题是:

1)我希望从中获取区域(Dean、Princial 等)和子区域(添加、编辑等)值 HTML 表单只是不像我在 php 部分中创建的那样再次创建数组?

2) 还要计算仅检查的区域和子区域的大小,因为区域和子区域的大小
分区不同,要运行两个for循环将数据插入数据库表吗?

请指导我该怎么办?

谢谢

最佳答案

嗨,如果您的问题仅与循环有关,请尝试此操作。

$post_val = $_POST['permission'];   
foreach($post_val as $key=>$value)
{
$x1 = $key;
for($i=0;$i<count($value);$i++)
{
$x2 = $value[$i];
mysqli_query($connection,"INSERT INTO upermission (area, subarea) VALUES
('".$x1."','".$x2."')");
}
}

如果您只想在 HTML 中构建所有这些,那么您必须处理 javascript 或 jQuery。

关于PHP HTML 形式多维数组 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27033342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com