PHP 页面循环显示tr td 里面放值
php checkbox html
<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <?php $i = 0; foreach($info['list'] as $ent){ $ent = $ent['info']; $checked = $ent['flag']==1?"checked='checked'":""; echo '<td>'; echo '<input id="view_'.$i.'" class="Sedd" type="checkbox" value="'.$ent["code"].'" name="view[]" '.$checked.'>'; echo ' '; echo '<label for="view_'.$i.'">'.$ent["name"].'</label>'; echo ' '; echo '</td>'; $i ++; } ?> </tr></table>
---------------------------------
现在显示出来的效果是:
------------------------------------
我想要排出来的效果如下:
代码已经贴出来了,求大虾帮我改一下排版显示效果
回复讨论(解决方案)
<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <?php $i=0; foreach($info['list'] as $ent){ $ent = $ent['info']; $checked = $ent['flag']==1?"checked='checked'":""; }?> <td> <input id="view_<?php echo $i;?>" class="Sedd" type="checkbox" value="<?php echo $ent["code"];?>" name="view[]" <?php echo $checked;?>> <label for="view_<?php echo $i;?>"><?php echo $ent["name"];?></label> </td> <?php if(($i+1)%4==0){?></tr><tr><?php }?> <?php $i++; }?> </tr></table>
<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <?php $i=0; foreach($info['list'] as $ent){ $ent = $ent['info']; $checked = $ent['flag']==1?"checked='checked'":""; }?> <td> <input id="view_<?php echo $i;?>" class="Sedd" type="checkbox" value="<?php echo $ent["code"];?>" name="view[]" <?php echo $checked;?>> <label for="view_<?php echo $i;?>"><?php echo $ent["name"];?></label> </td> <?php if(($i+1)%4==0){?></tr><tr><?php }?> <?php $i++; }?> </tr></table>
大虾:
为什么
$i++;
}?>
说这里多了一个} 我删除掉之后 就报
$checked = $ent['flag']==1?"checked='checked'":""; 这一行代码错误
<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <?php $i=0; foreach($info['list'] as $ent){ $ent = $ent['info']; $checked = $ent['flag']==1?"checked='checked'":""; }?> <td> <input id="view_<?php echo $i;?>" class="Sedd" type="checkbox" value="<?php echo $ent["code"];?>" name="view[]" <?php echo $checked;?>> <label for="view_<?php echo $i;?>"><?php echo $ent["name"];?></label> </td> <?php if(($i+1)%4==0){?></tr><tr><?php }?> <?php $i++; }?> </tr></table>
大虾:
为什么
$i++;
}?>
说这里多了一个} 我删除掉之后 就报
$checked = $ent['flag']==1?"checked='checked'":""; 这一行代码错误
一开始系统报 多了一个括号} 说多一个} ,那么我删除掉 }.
可是接着又报$checked = $ent['flag']==1?"checked='checked'":""; 这行代码错误!
我写多了一个好像,最下面那个}号是foreach的结束。你试试下面这段:
<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <?php $i=0; foreach($info['list'] as $ent){ $ent = $ent['info']; $checked = $ent['flag']==1?"checked='checked'":""; ?> <td> <input id="view_<?php echo $i;?>" class="Sedd" type="checkbox" value="<?php echo $ent["code"];?>" name="view[]" <?php echo $checked;?>> <label for="view_<?php echo $i;?>"><?php echo $ent["name"];?></label> </td> <?php if(($i+1)%4==0){?></tr><tr><?php }?> <?php $i++; }?> </tr></table>
$checked = $ent['flag']==1?"checked='checked'":"";
说这行报错!
我写多了一个好像,最下面那个}号是foreach的结束。你试试下面这段:
<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <?php $i=0; foreach($info['list'] as $ent){ $ent = $ent['info']; $checked = $ent['flag']==1?"checked='checked'":""; ?> <td> <input id="view_<?php echo $i;?>" class="Sedd" type="checkbox" value="<?php echo $ent["code"];?>" name="view[]" <?php echo $checked;?>> <label for="view_<?php echo $i;?>"><?php echo $ent["name"];?></label> </td> <?php if(($i+1)%4==0){?></tr><tr><?php }?> <?php $i++; }?> </tr></table>
$checked = $ent['flag']==1?"checked='checked'":"";
说这行报错!
这段html没错的。我测试过了。检查你的info数组,是否有authflag这个key.
print_r($info);打印出来看看$info里面的数据的情况。
针对你的html,我给了一段模拟的数组:
$info=array('list'=>array( array('info'=>array('flag'=>1,'code'=>1,'name'=>1)), array('info'=>array('flag'=>0,'code'=>2,'name'=>2)), array('info'=>array('flag'=>1,'code'=>3,'name'=>3)), array('info'=>array('flag'=>0,'code'=>4,'name'=>4)), array('info'=>array('flag'=>0,'code'=>5,'name'=>5)), array('info'=>array('flag'=>0,'code'=>6,'name'=>6)), array('info'=>array('flag'=>0,'code'=>7,'name'=>7)), array('info'=>array('flag'=>0,'code'=>8,'name'=>8)), ));
<table width="100%" border="0" cellspacing="0" cellpadding="0"> <!--<tr> 这个tr移动到循环中 --> <?php $i = 0; foreach($info['list'] as $ent){if($i % 4 == 0) echo '<tr>'; //注意这里 $ent = $ent['info']; $checked = $ent['flag']==1?"checked='checked'":""; echo '<td>'; echo '<input id="view_'.$i.'" class="Sedd" type="checkbox" value="'.$ent["code"].'" name="view[]" '.$checked.'>'; echo ' '; echo '<label for="view_'.$i.'">'.$ent["name"].'</label>'; echo ' '; echo '</td>'; $i ++;if($i % 4 == 0) echo '</tr>'; //注意这里 } ?> <?php echo $i % 4 ? '</tr>' : ''; //注意这里 ?></table>
这段html没错的。我测试过了。检查你的info数组,是否有authflag这个key.
print_r($info);打印出来看看$info里面的数据的情况。
针对你的html,我给了一段模拟的数组:
$info=array('list'=>array( array('info'=>array('flag'=>1,'code'=>1,'name'=>1)), array('info'=>array('flag'=>0,'code'=>2,'name'=>2)), array('info'=>array('flag'=>1,'code'=>3,'name'=>3)), array('info'=>array('flag'=>0,'code'=>4,'name'=>4)), array('info'=>array('flag'=>0,'code'=>5,'name'=>5)), array('info'=>array('flag'=>0,'code'=>6,'name'=>6)), array('info'=>array('flag'=>0,'code'=>7,'name'=>7)), array('info'=>array('flag'=>0,'code'=>8,'name'=>8)), ));
有的[authflag] => 1
--------------------------------------------------
" name="view_[]" >报错
说这行也报错的
<table width="100%" border="0" cellspacing="0" cellpadding="0"> <!--<tr> 这个tr移动到循环中 --> <?php $i = 0; foreach($info['list'] as $ent){if($i % 4 == 0) echo '<tr>'; //注意这里 $ent = $ent['info']; $checked = $ent['flag']==1?"checked='checked'":""; echo '<td>'; echo '<input id="view_'.$i.'" class="Sedd" type="checkbox" value="'.$ent["code"].'" name="view[]" '.$checked.'>'; echo ' '; echo '<label for="view_'.$i.'">'.$ent["name"].'</label>'; echo ' '; echo '</td>'; $i ++;if($i % 4 == 0) echo '</tr>'; //注意这里 } ?> <?php echo $i % 4 ? '</tr>' : ''; //注意这里 ?></table>
版主出马 果然牛X

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

长URL(通常用关键字和跟踪参数都混乱)可以阻止访问者。 URL缩短脚本提供了解决方案,创建了简洁的链接,非常适合社交媒体和其他平台。 这些脚本对于单个网站很有价值

在Facebook在2012年通过Facebook备受瞩目的收购之后,Instagram采用了两套API供第三方使用。这些是Instagram Graph API和Instagram Basic Display API。作为开发人员建立一个需要信息的应用程序

Laravel使用其直观的闪存方法简化了处理临时会话数据。这非常适合在您的应用程序中显示简短的消息,警报或通知。 默认情况下,数据仅针对后续请求: $请求 -

这是有关用Laravel后端构建React应用程序的系列的第二个也是最后一部分。在该系列的第一部分中,我们使用Laravel为基本的产品上市应用程序创建了一个RESTFUL API。在本教程中,我们将成为开发人员

Laravel 提供简洁的 HTTP 响应模拟语法,简化了 HTTP 交互测试。这种方法显着减少了代码冗余,同时使您的测试模拟更直观。 基本实现提供了多种响应类型快捷方式: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

PHP客户端URL(curl)扩展是开发人员的强大工具,可以与远程服务器和REST API无缝交互。通过利用Libcurl(备受尊敬的多协议文件传输库),PHP curl促进了有效的执行

您是否想为客户最紧迫的问题提供实时的即时解决方案? 实时聊天使您可以与客户进行实时对话,并立即解决他们的问题。它允许您为您的自定义提供更快的服务

2025年的PHP景观调查调查了当前的PHP发展趋势。 它探讨了框架用法,部署方法和挑战,旨在为开发人员和企业提供见解。 该调查预计现代PHP Versio的增长
