可能有点儿,因为我已经使用了这个,我想我一直在看这个。只是看不出我明显错过的东西。
我正在尝试查询分配给已终止团队成员的记录,并在该查询中执行第二个查询,其中显示了在选择菜单中使用的团队成员。允许将已终止团队成员的记录分配给已聘用的团队成员。
我正在使用将以下值传递给POST的表单:
<?php
//Loop Through all records in Select Query
foreach ($TMReservesResult as $Record=>$Value){
?>
<?php //var_dump($Value); ?>
<td><?php echo $Value['Company Name']; ?></td>
<td><?php echo $Value['PhoneNumber']; ?></td>
<td><?php echo $Value['State']; ?></td>
<?php
//STRIP TIME FROM DATE STRING
$str = $Value['CallDate'];
$res = $Value['Call Back Date'];
?>
<td><?php echo substr($str, 0, 11); ?></td>
<td><?php echo substr($res, 0, 11); ?></td>
<td>
<center>
<div class="form-group">
<div class="col-lg-12 col-md-12 col-sm-12">
<select class="form-control" name="UserName">
<?php foreach($FindActiveTMNamesResults AS $TMNames=>$TMs) { ?>
<option value="<?php echo $TMs['UserName']; ?>"><?php echo $TMs['UserName']; ?></option>
<?php } ?>
</select>
</div>
</div>
</center>
</td>
</tr>
<input type="hidden" name="ContactID[]" value="<?php echo $Value["ContactID"]; ?>" />
<?php } ?>
处理POST值:
<?php
if (isset($_POST["submit"])){
//update Employee Info
$ContactID = Escape_Function($_POST["ContactID"]);
$UserName = Escape_Function(($_POST["UserName"]));
foreach($ContactID as $id){
//Update Query
$UpdateEmployeeQuery = 'UPDATE [ACR Contact Management].[dbo].[Contacts] SET [LeadGenerator] = \'' . $UserName . '\' WHERE [ContactID] = \'' . $id . '\'';
$UpdateEmployeeResult = $DB->query($UpdateEmployeeQuery);
}
}
?>
结果
<?php
var_dump($UpdateEmployeeQuery);
?>
string(113)&#34; UPDATE [ACR Contact Management]。[dbo]。[Contacts] SET [LeadGenerator] =&#39; sbarnes&#39;在哪里[ContactID] =&#39; 1362718628&#39;&#34; string(113)&#34; UPDATE [ACR Contact Management]。[dbo]。[Contacts] SET [LeadGenerator] =&#39; sbarnes&#39;在哪里[ContactID] =&#39; 1362703257&#39;&#34; string(113)&#34; UPDATE [ACR Contact Management]。[dbo]。[Contacts] SET [LeadGenerator] =&#39; sbarnes&#39;在哪里[ContactID] =&#39; 1364930874&#39;&#34; string(113)&#34; UPDATE [ACR Contact Management]。[dbo]。[Contacts] SET [LeadGenerator] =&#39; sbarnes&#39;在哪里[ContactID] =&#39; 1364930900&#39;&#34; string(113)&#34; UPDATE [ACR Contact Management]。[dbo]。[Contacts] SET [LeadGenerator] =&#39; sbarnes&#39;在哪里[ContactID] =&#39; 1364930976&#39;&#34;
看来我的ID循环工作正常,但是,循环(或缺少)只抓取最后一个记录终止团队成员名称。
我错过了什么?先谢谢你。
答案 0 :(得分:0)
更改
<select class="form-control" name="UserName">
到
<select class="form-control" name="UserName[]">
页面(您处理POST值的位置)
<?php
if (isset($_POST["submit"])) {
for($i = 0; $i < sizeof($_POST["ContactID"]);$i++){
$id = Escape_Function($_POST["ContactID"][$i]);
$UserName = Escape_Function($_POST["UserName"][$i]);
$UpdateEmployeeQuery = 'UPDATE [ACR Contact Management].[dbo].[Contacts] SET [LeadGenerator] = \'' . $UserName . '\' WHERE [ContactID] = \'' . $id . '\'';
$UpdateEmployeeResult = $DB->query($UpdateEmployeeQuery);
}
}?>
您将ContactId作为数组传递,但未将username作为数组类型传递。因此,它采用了最后一次下拉选项。将其更改为数组类型并循环以迭代每条记录。