我在现有数组中添加了一个新数组,但布局已损坏。
输出数组的代码是:
for ($i=1; $i<=$comp_value_count; $i++) {
$compPro = 'pro'.$i;
$attrCount = $result[$compPro][11];//A count of how many options there are per product
$compDescription .= '<td>' . $result[$compPro][2] . '</td>';
$compModel .= '<td>' . $result[$compPro][3] . '</td>';
$compWeight .= '<td>' . $result[$compPro][4] . '</td>';
$compQuantity .= '<td>' . $result[$compPro][5] . '</td>';
$compManufacturer .= '<td>' . $result[$compPro][7] . '</td>';
$compattr1 .= '<td>';
for ($c=0; $c<=$attrCount; $c++){
$compattr2 .= $result[$compPro][8][$c] . $result[$compPro][9][$c] . "\n";
}
$compattr3 .= '</td>';
}
// create the display
echo '<tr class="rowEven"><th>' . COMPARE_QUANTITY . '</th>' . $compQuantity . '</tr>';
echo '<tr class="rowOdd"> <th>' . COMPARE_MODEL . '</th>' . $compModel . '</tr>';
echo '<tr class="rowEven"><th>' . COMPARE_WEIGHT . '</th>' . $compWeight . '</tr>';
echo '<tr class="rowOdd"> <th>' . COMPARE_MANUFACTURER . '</th>' . $compManufacturer . '</tr>';
echo '<tr class="rowEven"><th>' . COMPARE_DESC . '</th>' . $compDescription . '</tr>';
echo '<tr class="rowOdd"> <th>' . COMPARE_OPTNAME . '</th>' . $compattr1 . $compattr2 . $compattr3 . '</tr>';
echo '</table>';
}
显示此代码生成的布局的小提琴是https://jsfiddle.net/uzmk61v7/2/
另一个显示我想要它的样子是https://jsfiddle.net/85wztu3z/1/
var_dump($ result)输出低于
array(2) {
["pro1"]=> array(12) {
[0]=> string(191) "01 button stainless steel audio panel - surface"
[1]=> string(612) "01 button stainless steel audio panel - surface"
[2]=> string(144) "5101S - 1 button audio door entry phone intercom panel SRS surface mounted, vandal resistant 1 way traditional audio, BS316 stainless steel,..."
[3]=> string(5) "5101S"
[4]=> string(1) "0"
[5]=> string(1) "1"
[6]=> string(171) "£147.74 Inc VAT £123.12 Ex VAT"
[7]=> string(3) "SRS"
[8]=> array(4) {
[0]=> string(12) "Call Buttons"
[1]=> string(8) "Mounting"
[2]=> string(6) "Finish"
[3]=> string(5) "Range"
}
[9]=> array(4) {
[0]=> string(20) "1 call button"
[1]=> string(20) "Surface mount"
[2]=> string(35) "Stainless Steel VR (brushed)"
[3]=> string(15) "SRS 5000"
}
[10]=> string(73) "remove"
[11]=> string(1) "4"
}
["pro2"]=> array(12) {
[0]=> string(200) "00 way VR brass video panel, size D"
[1]=> string(576) "00 way VR brass video panel, size D"
[2]=> string(148) "6600 - 0 button video door entry phone intercom panel Size D SRS vandal resistant 0 way traditional video, polished brass, engravable, door entry..."
[3]=> string(4) "6600"
[4]=> string(1) "0"
[5]=> string(1) "0"
[6]=> string(171) "£155.95 Inc VAT £129.96 Ex VAT"
[7]=> string(3) "SRS"
[8]=> array(4) {
[0]=> string(8) "Mounting"
[1]=> string(6) "Finish"
[2]=> string(5) "Range"
[3]=> string(7) "Cabling"
}
[9]=> array(4) {
[0]=> string(18) "Flush mount"
[1]=> string(21) "Polished brass"
[2]=> string(15) "SRS 4000"
[3]=> string(34) "SRS Video C + 6 + n cabling"
}
[10]=> string(73) "remove" [11]=> string(1) "4"
}
}
有关如何解决此问题的任何建议?
答案 0 :(得分:0)
再添加一个<td></td>
for ($i=1; $i<=$comp_value_count; $i++) {
$compPro = 'pro'.$i;
$attrCount = $result[$compPro][11];//A count of how many options there are per product
$compDescription .= '<td>' . $result[$compPro][2] . '</td>';
$compModel .= '<td>' . $result[$compPro][3] . '</td>';
$compWeight .= '<td>' . $result[$compPro][4] . '</td>';
$compQuantity .= '<td>' . $result[$compPro][5] . '</td>';
$compManufacturer .= '<td>' . $result[$compPro][7] . '</td>';
$compattr1 .= '<td>';
for ($c=0; $c<=$attrCount; $c++){
$compattr1 .= $result[$compPro][8][$c] . "\n";
}
$compattr1 .= '</td>';
$compattr2 .= '<td>';
for ($c=0; $c<=$attrCount; $c++){
$compattr2 .= $result[$compPro][9][$c] . "\n";
}
$compattr2 .= '</td>';
}
// create the display
echo '<tr class="rowEven"><th>' . COMPARE_QUANTITY . '</th>' . $compQuantity . '</tr>';
echo '<tr class="rowOdd"> <th>' . COMPARE_MODEL . '</th>' . $compModel . '</tr>';
echo '<tr class="rowEven"><th>' . COMPARE_WEIGHT . '</th>' . $compWeight . '</tr>';
echo '<tr class="rowOdd"> <th>' . COMPARE_MANUFACTURER . '</th>' . $compManufacturer . '</tr>';
echo '<tr class="rowEven"><th>' . COMPARE_DESC . '</th>' . $compDescription . '</tr>';
echo '<tr class="rowOdd"> <th>' . COMPARE_OPTNAME . '</th>' . $compattr1 . $compattr2 . '</tr>';
echo '</table>';