由于这个错误我感到很沮丧。当我在不使用任何框架的情况下编程php时,我的代码是可以的,但是当我在codeigniter中传输它时,它总是说严重性未定义的函数。请检查我发布的代码:
foreach($data['employee'] as $val)
{
if($val['Active']==0)
{
$status = @strtoupper('Resigned');
}
else
{
$status = @strtoupper('Active');
}
$str = @substr($val['WS_Code'],0,-2);
if($str == "PR")
{
$line = @substr($val['WS_Code'],0,-1);
$str2 = @substr($val['WS_Code'],-1);
if($str2 == 'B')
{
$section = "BRIEF";
}
else
{
$section = "PANTY";
}
}
elseif($str == "SP")
{
$line = @substr($val['WS_Code'],0,-1);
$str2 = @substr($val['WS_Code'],-1);
if($str2 == "B")
{
$section = "BRIEF";
}
else
{
$section = "PANTY";
}
}
elseif($str == "BL")
{
$section = "BRIEF";
$str2 = @substr($str,-3,2);
$line = $str2;
}
elseif($str == "PL")
{
$section = "PANTY";
$str2 = @substr($str,-3,2);
$line = $str2;
}
以下是代码的其余部分以及我如何使用它:
<tr>
<td><label class='control-label'>Section:</label></td>
<td>
<select class='form-control' name='cmbsection' id='cmbsection'>
<option value='".$section."'>".$section."</option>
";
$section_code = array();
$section_code[] = $section;
foreach($data['sectionlist'] as $value)
{
if(!in_array($value['sectionName'],$section_code))
{
echo "<option value='".$value['sectionName']."'>".$value['sectionName']."</option>";
}
}
echo "
</select>
</td>
<td><label class='control-label'>Line:</label></td>
<td>
<select class='form-control' name='cmbline' id='cmbline'>
";
$line_code = array();
$line_code[] = $line;
echo "
<option value='$line'>$line</option>
";
foreach($data['linelist'] as $value)
{
if(!in_array($value['lineName'],$line_code))
{
echo "<option value='".$value['lineName']."'>".$value['lineName']."</option>";
}
}
echo "
</select>
</td>
</tr>
请注意,我正在回显控制器内的表格,错误始终指向$section
代码中的$line
和if(!in_array($value['lineName'],$line_code))
。
答案 0 :(得分:2)
我不会称这是一个很好的解决方案,但它至少会确保变量$line
和$section
存在。
您的问题是您在WS_Code
获得了一个您没有处理的代码。如果您只看到已编码的代码,则只创建2个变量,您必须拥有一个您没有预期和编码的新代码。
正确的解决方案是找出您在此代码中未获得的WS_Code
内容。
事实上,正确的解决方案是创建一个包含code
和full_desc
的表格,您可以查询这些表格,以便将这些代码扩展为您想要使用的完整描述,并确保当创建新代码时,表格会相应更新
$line = 'new unexpected code recieved';
$section = 'new unexpected section recieved';
foreach($data['employee'] as $val)
{
if($val['Active']==0) {
$status = strtoupper('Resigned');
} else {
$status = strtoupper('Active');
}
$str = substr($val['WS_Code'],0,-2);
if($str == "PR") {
$line = substr($val['WS_Code'],0,-1);
$str2 = substr($val['WS_Code'],-1);
if($str2 == 'B') {
$section = "BRIEF";
} else {
$section = "PANTY";
}
}
elseif($str == "SP") {
$line = substr($val['WS_Code'],0,-1);
$str2 = substr($val['WS_Code'],-1);
if($str2 == "B") {
$section = "BRIEF";
} else {
$section = "PANTY";
}
}
elseif($str == "BL") {
$section = "BRIEF";
$str2 = substr($str,-3,2);
$line = $str2;
}
elseif($str == "PL") {
$section = "PANTY";
$str2 = substr($str,-3,2);
$line = $str2;
}
答案 1 :(得分:-1)
请使用以下代码:
if(isset($line)){
echo "<option value='$line'>$line</option>";
}
foreach($data['linelist'] as $value){
if(isset($value['lineName']) && isset($line_code)) {
if (!in_array($value['lineName'], $line_code)) {
echo "<option value='" . $value['lineName'] . "'>" . $value['lineName'] . "</option>";
}
}
}