我有以下功能,PHP表格处理从维数组
<pre>
public function getFree($cp) {
global $glb_con;
try {
$sql = "SELECT p.ID, w.ID, p.fname, p.lname, w.desc FROM weight w
INNER JOIN comp t ON w.wcl = t.cmp AND w.wc = t.cm
INNER JOIN pers b ON w.ID = b.ID_l
INNER JOIN pn p ON b.ID = p.ID
AND t.cp=:cp group";
$query = $glb_connection->prepare($sql);
$query->bindValue(':cp',$cp);
$query->execute();
$wes = $query->fetchAll();
// First array Generated from sql1 query
$newCorr = array();
foreach ($wes as $option) {
$wclID = $option['desc'];
$nameF = $option['fname'];
$nameL = $option['lname'];
$id = $option['ID'];
$newCorr[$wclID][$id] = $nameL." ".$nameF;
}
$sql2 = "SELECT p.ID, e.enre w.ID, p.fname, p.lname, w.desc FROM weight w
INNER JOIN comp t ON w.wcl = t.cmp AND w.wc = t.cm
INNER JOIN pers b ON w.ID = b.ID_l
INNER JOIN pn p ON b.ID = p.ID
INNER JOIN t_ent e ON e.ID = p.ID
AND t.cp=:cp group";
$query = $glb_connection->prepare($sql2);
$query->bindValue(':ID_cmp',$ID_cmp);
$query->execute();
$wes1 = $query->fetchAll();
//the second array from sql2 query
$newCorrAc = array();
foreach ($wes1 as $option) {
$wc = $option['desc'];
$ent = $option['enre'];
$nameF = $option['fname'];
$nameL = $option['lname'];
$id = $option['ID'];
$newCorrAc [$wc] [$id] [$ent]= $nameL." ".$nameF;
}
//the form will generate after here here
$html_form = '';
if(count($newCorr) == 0){
$html_form .= '<p>'.boz(_('Not Found!')).'</p>';
} else {
$html_form .= '<form id="checkEnt" name="checkEnt" method="post" action="r.php?cp=<?=$cp?>">';
$html_form .= '<input type="hidden" value="checkEntrance" name="ent">';
$html_form .= '<table class="table zebra-striped table-bordered table-striped span8">';
$html_form .= '<tbody>';
foreach ($newCorr as $orgKey => $list) {
$html_form .= '<tr><td width="5%">';
$html_form .= '<h5>'.$orgKey.'kg</h5>';
$html_form .= '</td>
<td width="10%">
<label class="control-label" for="inputWei">Boxer</label>';
$html_form .= '<select class="input-xlarge" id="input" name="drop[0][]">';
$html_form .= '<option value="">Select</option>';
foreach ($list as $key => $value) {
$html_form .= '<option value='.$key.'>'.$value.'</option>';
}
$html_form .= '</select>
</td>
<td width="10%">
<label class="control-label" for="inputWei">Res</label>
<select class="input-xlarge" name="drop[1][]">';
$html_form .= '<option value="">Select</option>
<option value="en">Ent</option>
<option value="re">Res</option>
</select>
</td>
</tr>';
}
$html_form .= '<tr><td colspan="3">
<div class="modal-footer">
<button type=reset class="btn btn-danger">Reset</button>
<button class="btn btn-primary" ID="btnSaveBoxer">Save</button>
</div>
</td>
</tr>
</tbody>
</table>
</form>';
}
echo $html_form;
} catch(PDOException $e) {
addError($e->getMessage(), "MySql-Error", "error");
}
}
</pre>
它的作用是完全...第一个SQL中使用fetchall方法返回数组,有点变化后的结果会是怎样此...
//首先查询结果阵列检查该线
$ newCorr [$ wclID] [$ ID] = $ NAMEL“” $ NAMEF。;
<pre>
Array
(
[4-6] => Array
(
[87] => haha lala
)
[8] => Array
(
[25] => sasa baba
[24] => mama fafa
[26] => tata lala
)
[5] => Array
(
[29] => papa oaoa
[27] => laha mana
[30] => salam sara
)
[2] => Array
(
[33] => tata kaka
[32] => lala sasa
[31] => Papa lama
[34] => wana michel
)
[6] => Array
(
[35] => zaza yaya
[37] => wana mata
[36] => Kaku luba
)
)
</pre>
从上面的代码中可以看到,我生成了从上面的数组填充的下拉表单。
我面临什么问题,客户输入的表单数据后,当我需要填充的形式,因为它是除客户选择,必须选择为默认...
所以,我做了什么是我使用第二个SQL2,它生成以下数组,这个数组正是客户输入的数组。
//第二查询结果数组 $ newCorrAc [$ wc] [$ id] [$ ent] = $ nameL。“”。$ nameF;
<pre>
Array
(
[8] => Array
(
[26] => Array
(
[ent] => tata lala
)
)
[2] => Array
(
[31] => Array
(
[res] => papa lama
)
)
)
</pre>
的主要问题是,我怎么能够从他/她先前输入的数据填写表格时,下拉填充一次?
总之,我想要做的是,形式submited,我有链接进行更正。如果点击它应该显示相同的形式,除了之前输入的数据,可以从数据库中获得。
有一些想法吗?
如何将加载的数据添加到每个字段的'value'值?或者对于下拉菜单,将'selected =“selected”'添加到匹配数据库条目的选项。 – UrGuardian4ngel
你是怎么表达的?你能详细说一下吗? –
您想使用客户输入的值预先填充生成的表单。在生成表单时,可以使用'value'属性为** input元素**设置'default'值。 ''。对于**下拉菜单**,您可以添加'selected =“选中”'。 ''。 – UrGuardian4ngel