一个输出格式的问题

littlebirds 2009-07-16 10:33:24
我的格式如下:
Bin(WRIGHT NT) Test Item
Bin1 -
Bin2 -
Bin3 61
Bin4 50
Bin5 30
Bin6 100
Bin7 1
Bin8 118

代码如下:

<table border="0" align="right" cellpadding="0" cellspacing="1" bgcolor="#B0C5FF" width="600">
<tr class="cells" onmouseover="this.className='cells2'" onmouseout="this.className='cells'"><td bgColor=#cedcff width=30%><strong>Bin(WRIGHT NT)</strong></td><td bgColor=#cedcff width=40%><strong>Test Item</strong></td></tr>
<?php
function foo($s, $t) {
$p = split('\|', $s);
do{
//print_r($p);
$n = array_search(max($p), $p);
//if(@in_array($n, $t)) return $n;
if(@in_array($n, $t) && max($p)!=0) return $n;
unset($p[$n]);
}while($p);
return '-';
}

foreach($arr3 as $bin => $binItem)
{
?>
<tr class="cells" onmouseover="this.className='cells2'" onmouseout="this.className='cells'"><td width=50%><?php echo "Bin".$bin;?></td><td width=50%>
<?php
echo foo($binItem, $bin2test_item[$bin]);
?></td></tr>
<?php
}
?>
</table>

能不能把格式变成这个样子?将bin1和bin2的项去除,从bin3开始循环,直到bin8?
Bin(WRIGHT NT) Test Item
Bin3 61
Bin4 50
Bin5 30
Bin6 100
Bin7 1
Bin8 118

请教各位如何实现?
...全文
34 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
littlebirds 2009-07-17
  • 打赏
  • 举报
回复
谢谢!
unset()函数可以使用。
littlebirds 2009-07-16
  • 打赏
  • 举报
回复
Dut Bin(WRIGHT NT)
3 Bin 7
12 Bin 7
33 Bin 7
133 Bin 7
148 Bin 7
251 Bin 7
256 Bin 7
Bin(WRIGHT NT) Test Item
Bin1 -
Bin2 -
Bin3 61
Bin4 50
Bin5 30
Bin6 100
Bin7 1
Bin8 118

我现在要把这两张表合并,如下图:
Dut Bin(WRIGHT NT) Test Item
3 Bin 7 1
12 Bin 7 1
33 Bin 7 1
133 Bin 7 1
148 Bin 7 1
251 Bin 7 1
256 Bin 7 1

只显示对应bin的test item该怎么做?
tony-杨 2009-07-16
  • 打赏
  • 举报
回复
1、只是简单的去掉前两个的话 在foreach前加上array_shift( array_shift($arr3) )或unset($arr3[0], $arr3[1])
xuchenm 2009-07-16
  • 打赏
  • 举报
回复
改成这样试试看吧


<table border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#B0C5FF" width="600">
<tr class="cells" onmouseover="this.className='cells2'" onmouseout="this.className='cells'"><td bgColor=#cedcff width=30%><strong>Dut</strong></td><td bgColor=#cedcff width=40%><strong>Bin(WRIGHT NT)</strong></td><td bgColor=#cedcff width=30%><strong>Test Item</strong></td></tr>
<?php
function foo($s, $t) {
$p = split('\|', $s);
do{
//print_r($p);
$n = array_search(max($p), $p);
//if(@in_array($n, $t)) return $n;
if(@in_array($n, $t) && max($p)!=0) return $n;
unset($p[$n]);
}while($p);
return '-';
}

for($i=0;$i<count($save);$i++)
{
?>
<tr class="cells" onmouseover="this.className='cells2'" onmouseout="this.className='cells'">
<td width=30%>
<?php
echo trim($save[$i]);
?>
</td>
<td width=40%>
<?php
echo trim("Bin ".$resultsArray[$save[$i]]);
?>
</td>
<td width=30%>
<?php
foreach($arr3 as $bin => $binItem)
{
if ($bin == $resultsArray[$save[$i]] )
echo foo($binItem, $bin2test_item[$bin]);
}
?>
</td>
<?php
}
?>
</tr>
</table>

littlebirds 2009-07-16
  • 打赏
  • 举报
回复
忘了贴代码了-_-!! :

table1:
<table border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#B0C5FF" width="600">
<tr class="cells" onmouseover="this.className='cells2'" onmouseout="this.className='cells'"><td bgColor=#cedcff width=30%><strong>Dut</strong></td><td bgColor=#cedcff width=40%><strong>Bin(WRIGHT NT)</strong></td></tr>
<?php
for($i=0;$i<count($save);$i++)
{
?>
<tr class="cells" onmouseover="this.className='cells2'" onmouseout="this.className='cells'"><td width=30%>
<?php
echo trim($save[$i]);
?>
<td width=70%>
<?php
echo trim("Bin ".$resultsArray[$save[$i]]);
?></td>
<?php
}
?>
</tr>
</table>

table2:
<table border="0" align="right" cellpadding="0" cellspacing="1" bgcolor="#B0C5FF" width="600">
<tr class="cells" onmouseover="this.className='cells2'" onmouseout="this.className='cells'"><td bgColor=#cedcff width=30%><strong>Bin(WRIGHT NT)</strong></td><td bgColor=#cedcff width=40%><strong>Test Item</strong></td></tr>
<?php
function foo($s, $t) {
$p = split('\|', $s);
do{
//print_r($p);
$n = array_search(max($p), $p);
//if(@in_array($n, $t)) return $n;
if(@in_array($n, $t) && max($p)!=0) return $n;
unset($p[$n]);
}while($p);
return '-';
}

foreach($arr3 as $bin => $binItem)
{
?>
<tr class="cells" onmouseover="this.className='cells2'" onmouseout="this.className='cells'"><td width=50%><?php echo "Bin".$bin;?></td><td width=50%>
<?php
echo foo($binItem, $bin2test_item[$bin]);
?></td></tr>
<?php
}
?>
</table>

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧