我在下面的代码中创建了一个php表单。即使没有从shoe_sizes或color_value中选择任何内容,我也无法弄清楚如何使输出文件具有PartColor:行。
目前它将所有大小的行添加到输出文件中,即使没有数据但是在没有选择时没有添加PartColor:行。
foreach ($data['Saleslead']['style_numbers'] as $key => $value) {
$comma_delmited_list .= "---- Start Product ----\n";
$comma_delmited_list .= "\n";
$color_value = $data['Saleslead']['colors'][$key];
$shoe_sizes = $data['Saleslead']['shoe_sizes'][$key];
$part_number = $style_number_complete_list[$data['Saleslead']['style_number_id'][$key]]['name'];
$color_range = $style_number_complete_list[$data['Saleslead']['style_number_id'][$key]]['color_range'];
$comma_delmited_list .= "PartNumber: ".$part_number."\n";
$comma_delmited_list .= "PartColorRange: ".$color_range."\n";
if($shoe_sizes != "" || $color_value != ""){
$texttoshow = "";
if($shoe_sizes != "" && $color_value != ""){
$texttoshow = $shoe_sizes;
}else if ($shoe_sizes != "" && $color_value == ""){
$texttoshow = $shoe_sizes;
}else if ($shoe_sizes == "" && $color_value != ""){
$texttoshow = $color_value;
}
$comma_delmited_list .= "PartColor: ".$texttoshow."\n";
}
$comma_delmited_list .= "cur_UnitPriceUserEntered: ".$data['Saleslead']['unit_price'][$key]."\n";
$comma_delmited_list .= "OrderInstructions: ".$data['Saleslead']['order_instruction'][$key]."\n";
$comma_delmited_list .= "Size01_Req: ".$data['Saleslead']['small'][$key]."\n";
$comma_delmited_list .= "Size02_Req: ".$data['Saleslead']['medium'][$key]."\n";
$comma_delmited_list .= "Size03_Req: ".$data['Saleslead']['large'][$key]."\n";
$comma_delmited_list .= "Size04_Req: ".$data['Saleslead']['xlarge'][$key]."\n";
$comma_delmited_list .= "Size05_Req: ".$data['Saleslead']['2xlarge'][$key]."\n";
$comma_delmited_list .= "Size06_Req: ".(isset($data['Saleslead']['other'][$key])?$data['Saleslead']['other'][$key]:"")."\n";
$comma_delmited_list .= "\n";
$comma_delmited_list .= "---- End Product ----\n";
$comma_delmited_list .= "\n";
以下是提交表单后的文字内容。
PartNumber:00021
PartColorRange:Darks
cur_UnitPriceUserEntered:21
OrderInstructions:
Size01_Req:21
Size02_Req:
Size03_Req:
Size04_Req:
Size05_Req:
Size06_Req:
我需要PartColor:在PartColorRange下面:
感谢您的帮助!
更新*按以下法案回答。
if($shoe_sizes != "" || $color_value != ""){
$texttoshow = "";
if($shoe_sizes != "" && $color_value != ""){
$texttoshow = $shoe_sizes;
}else if ($shoe_sizes != "" && $color_value == ""){
$texttoshow = $shoe_sizes;
}else if ($shoe_sizes == "" && $color_value != ""){
$texttoshow = $color_value;
}
$comma_delmited_list .= "PartColor: ".$texttoshow."\n";
} else {
$comma_delmited_list .= "PartColor: \n";
}
答案 0 :(得分:0)
这是因为如果PartColor:
或$shoe_sizes
不是空的,您只会添加$color_value
字符串。如果您希望else
显示,则可以在检查它们是否为空之后添加PartColor:
块。
if($shoe_sizes != "" || $color_value != "") {
// your code
} else {
$comma_delmited_list .= "PartColor: \n";
}