求一个格式输出的问题。 本帖最后由 lazygc520 于 2011-09-22 13:13:10 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <?php $i = 0; foreach($row1 as $k=>$v) { ?> <td><?php echo '<img src="test.php?codebar=BCGcode39extended&text='.$v.'">';?></td> <?php if($i%2 == 0){echo '</tr><tr>';} $i ++; } ?> </tr></table> 请把td的样式提到css文件中: <?php $k=0; foreach($row1 as $k=>$v) { if($k%2==0) echo '<tr><td ><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td>'; else echo '<td><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td></tr>'; $k++; } ?> 修改后的格式: <?php $k=0; foreach($row1 as $k=>$v) { if($k%2 == 0) { echo '<td colspan="3" rowspan="2" style="text-align: center; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; vertical-align: bottom; white-space: nowrap; border-left: .5pt solid windowtext; border-right: medium none; border-top: .5pt solid windowtext; border-bottom: .5pt solid black; padding: 0px"> <img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td>'; } else { echo '<td rowspan="2" style="text-align: center; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; vertical-align: bottom; white-space: nowrap; border-left: medium none; border-right: .5pt solid windowtext; border-top: medium none; border-bottom: .5pt solid black; padding: 0px"> <img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td>'; } $k++; } ?>现在的情况是3个条形码还在一排(同一个TR中),请问怎么解决? 你没有echo <tr></tr>这样的语句。。 <?php $k=0; foreach($row1 as $k=>$v) { if($k%2==0 && $k!=end($row1)) echo '<tr><td ><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td>'; else if($k%2==0 && $v==end($row1)) echo '<tr><td><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td></tr>'; else echo '<td><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td></tr>'; $k++; } ?> <?php $k=0; foreach($row1 as $k=>$v) { if($k%2==0 && $v!=end($row1)) echo '<tr><td ><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td>'; else if($k%2==0 && $v==end($row1)) echo '<tr><td><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td></tr>'; else echo '<td><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td></tr>'; $k++; } ?> 问题是这里只有两个TD,在同一个TR中。形式如下。这样能实现吗? 整个tr的内容如下:<tr height="26" style="height: 20.1pt"> <td height="26" style="height: 20.1pt; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; text-align: general; vertical-align: bottom; white-space: nowrap; border-left: .5pt solid windowtext; border-right: medium none; border-top: medium none; border-bottom: medium none; padding: 0px"> </td> <td colspan="3" rowspan="2" style="text-align: center; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; vertical-align: bottom; white-space: nowrap; border-left: .5pt solid windowtext; border-right: .5pt solid black; border-top: .5pt solid windowtext; border-bottom: .5pt solid black; padding: 0px"> <img src="test.php?codebar=BCGcode39extended&text=<?php echo $row['0']; ?>"></td> <?php $k=0; foreach($row1 as $k=>$v) { if($k%2 == 0) { echo '<td colspan="3" rowspan="2" style="text-align: center; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; vertical-align: bottom; white-space: nowrap; border-left: .5pt solid windowtext; border-right: medium none; border-top: .5pt solid windowtext; border-bottom: .5pt solid black; padding: 0px"> <img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td>'; } else { echo '<td rowspan="2" style="text-align: center; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; vertical-align: bottom; white-space: nowrap; border-left: medium none; border-right: .5pt solid windowtext; border-top: medium none; border-bottom: .5pt solid black; padding: 0px"> <img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td>'; } $k++; } ?> <td style="color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; text-align: general; vertical-align: bottom; white-space: nowrap; border-left: medium none; border-right: .5pt solid windowtext; border-top: medium none; border-bottom: medium none; padding: 0px"> </td> <td style="color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; text-align: general; vertical-align: bottom; white-space: nowrap; border: medium none; padding: 0px"> </td> </tr> 我已经调好了。感谢大家给我的思路。<tr height="26" style="height: 20.1pt"> <td height="26" style="height: 20.1pt; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; text-align: general; vertical-align: bottom; white-space: nowrap; border-left: .5pt solid windowtext; border-right: medium none; border-top: medium none; border-bottom: medium none; padding: 0px"> </td> <td colspan="3" rowspan="2" style="text-align: center; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; vertical-align: bottom; white-space: nowrap; border-left: .5pt solid windowtext; border-right: .5pt solid black; border-top: .5pt solid windowtext; border-bottom: .5pt solid black; padding: 0px"> <img src="test.php?codebar=BCGcode39extended&text=<?php echo $row['0']; ?>"></td> <td colspan="3" rowspan="2" style="text-align: center; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; vertical-align: bottom; white-space: nowrap; border-left: .5pt solid windowtext; border-right: .5pt solid black; border-top: .5pt solid windowtext; border-bottom: .5pt solid black; padding: 0px"> <?php foreach($row1 as $k=>$v) { if($k%2==0) echo '<img src="test.php?codebar=BCGcode39extended&text='.$v.'"> '; else echo '<img src="test.php?codebar=BCGcode39extended&text='.$v.'"><br />'; $k++; } ?></td> <td style="color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; text-align: general; vertical-align: bottom; white-space: nowrap; border-left: medium none; border-right: .5pt solid windowtext; border-top: medium none; border-bottom: medium none; padding: 0px"> </td> <td style="color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; text-align: general; vertical-align: bottom; white-space: nowrap; border: medium none; padding: 0px"> </td> </tr> 这样也可以,只是,判断的时候不直接echo,而是连接到不同的串里边。然后再echo连接好的串。 请教一个问题,使用什么加密方式可以把一个字符串变成一串纯数字 能连接mysql数据库服务器,但具体的数据库不可用??求解答 php参数问题 为什么在phpmyadmin里添加了密码后就进不去了 php 与ajax 交互的问题 武汉汉元科技招phper1-2名 关于类属性显式声明与隐式声明的问题 视频问题!!急!! mysql里面怎样进行内容追加的update? 使用phpexcel导入大量excel数据到mysql解决方案 ajax传来的json数据,php如何解析 虚拟主机session的问题
<tr>
<?php
$i = 0;
foreach($row1 as $k=>$v)
{
?>
<td><?php echo '<img src="test.php?codebar=BCGcode39extended&text='.$v.'">';?></td>
<?php
if($i%2 == 0){echo '</tr><tr>';}
$i ++;
}
?>
</tr>
</table>
$k=0;
foreach($row1 as $k=>$v)
{ if($k%2==0)
echo '<tr><td ><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td>';
else
echo '<td><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td></tr>';
$k++;
}
?>
$k=0;
foreach($row1 as $k=>$v)
{
if($k%2 == 0)
{
echo '<td colspan="3" rowspan="2" style="text-align: center; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; vertical-align: bottom; white-space: nowrap; border-left: .5pt solid windowtext; border-right: medium none; border-top: .5pt solid windowtext; border-bottom: .5pt solid black; padding: 0px">
<img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td>';
}
else
{
echo '<td rowspan="2" style="text-align: center; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; vertical-align: bottom; white-space: nowrap; border-left: medium none; border-right: .5pt solid windowtext; border-top: medium none; border-bottom: .5pt solid black; padding: 0px">
<img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td>';
}
$k++;
}
?>
现在的情况是3个条形码还在一排(同一个TR中),请问怎么解决?
你没有echo <tr></tr>这样的语句。。 <?php
$k=0;
foreach($row1 as $k=>$v)
{ if($k%2==0 && $k!=end($row1))
echo '<tr><td ><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td>';
else if($k%2==0 && $v==end($row1))
echo '<tr><td><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td></tr>';
else
echo '<td><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td></tr>';
$k++;
}
?>
$k=0;
foreach($row1 as $k=>$v)
{ if($k%2==0 && $v!=end($row1))
echo '<tr><td ><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td>';
else if($k%2==0 && $v==end($row1))
echo '<tr><td><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td></tr>';
else
echo '<td><img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td></tr>';
$k++;
}
?>
<td height="26" style="height: 20.1pt; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; text-align: general; vertical-align: bottom; white-space: nowrap; border-left: .5pt solid windowtext; border-right: medium none; border-top: medium none; border-bottom: medium none; padding: 0px">
</td>
<td colspan="3" rowspan="2" style="text-align: center; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; vertical-align: bottom; white-space: nowrap; border-left: .5pt solid windowtext; border-right: .5pt solid black; border-top: .5pt solid windowtext; border-bottom: .5pt solid black; padding: 0px">
<img src="test.php?codebar=BCGcode39extended&text=<?php echo $row['0']; ?>"></td>
<?php
$k=0;
foreach($row1 as $k=>$v)
{
if($k%2 == 0)
{
echo '<td colspan="3" rowspan="2" style="text-align: center; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; vertical-align: bottom; white-space: nowrap; border-left: .5pt solid windowtext; border-right: medium none; border-top: .5pt solid windowtext; border-bottom: .5pt solid black; padding: 0px">
<img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td>';
}
else
{
echo '<td rowspan="2" style="text-align: center; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; vertical-align: bottom; white-space: nowrap; border-left: medium none; border-right: .5pt solid windowtext; border-top: medium none; border-bottom: .5pt solid black; padding: 0px">
<img src="test.php?codebar=BCGcode39extended&text='.$v.'"></td>';
}
$k++;
}
?>
<td style="color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; text-align: general; vertical-align: bottom; white-space: nowrap; border-left: medium none; border-right: .5pt solid windowtext; border-top: medium none; border-bottom: medium none; padding: 0px">
</td>
<td style="color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; text-align: general; vertical-align: bottom; white-space: nowrap; border: medium none; padding: 0px"> </td>
</tr>
<td height="26" style="height: 20.1pt; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; text-align: general; vertical-align: bottom; white-space: nowrap; border-left: .5pt solid windowtext; border-right: medium none; border-top: medium none; border-bottom: medium none; padding: 0px">
</td>
<td colspan="3" rowspan="2" style="text-align: center; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; vertical-align: bottom; white-space: nowrap; border-left: .5pt solid windowtext; border-right: .5pt solid black; border-top: .5pt solid windowtext; border-bottom: .5pt solid black; padding: 0px">
<img src="test.php?codebar=BCGcode39extended&text=<?php echo $row['0']; ?>"></td>
<td colspan="3" rowspan="2" style="text-align: center; color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; vertical-align: bottom; white-space: nowrap; border-left: .5pt solid windowtext; border-right: .5pt solid black; border-top: .5pt solid windowtext; border-bottom: .5pt solid black; padding: 0px">
<?php
foreach($row1 as $k=>$v)
{
if($k%2==0)
echo '<img src="test.php?codebar=BCGcode39extended&text='.$v.'"> ';
else
echo '<img src="test.php?codebar=BCGcode39extended&text='.$v.'"><br />';
$k++;
}
?></td>
<td style="color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; text-align: general; vertical-align: bottom; white-space: nowrap; border-left: medium none; border-right: .5pt solid windowtext; border-top: medium none; border-bottom: medium none; padding: 0px">
</td>
<td style="color: windowtext; font-size: 12.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: 宋体; text-align: general; vertical-align: bottom; white-space: nowrap; border: medium none; padding: 0px">
</td>
</tr>
这样也可以,只是,判断的时候不直接echo,而是连接到不同的串里边。然后再echo连接好的串。