从数据库读出
$getdata1[xx]="王军_华科大_|军_科_|日日日_又由于_|";最终要实现:姓名 学校
---------------
王军 华科大
军 科
日日日 又由于代码如下,问题关键是不知道怎么把这个数组给循环打印出来,高手请教了:<?
$get1=mysql_query("select id,xx from per ;");
$getdata1=mysql_fetch_array($get1);
$fg=explode("|",$getdata1[xx]);
$g1=explode("_",$fg);
?>
<table border="1" align="center">
<tr align="center">
<td width="84">姓名</td>
<td width="99">学校</td>
<td width="89">操作</td>
</tr>
<?
foreach(){
}?>
</table>
$getdata1[xx]="王军_华科大_|军_科_|日日日_又由于_|";最终要实现:姓名 学校
---------------
王军 华科大
军 科
日日日 又由于代码如下,问题关键是不知道怎么把这个数组给循环打印出来,高手请教了:<?
$get1=mysql_query("select id,xx from per ;");
$getdata1=mysql_fetch_array($get1);
$fg=explode("|",$getdata1[xx]);
$g1=explode("_",$fg);
?>
<table border="1" align="center">
<tr align="center">
<td width="84">姓名</td>
<td width="99">学校</td>
<td width="89">操作</td>
</tr>
<?
foreach(){
}?>
</table>
解决方案 »
- PHP url重写表达式?
- 怎么从代码里面得到网页的源码?(类似chrome的开发人员工具)
- 要如何设置hosts文件?
- 求一段 替换 代码
- 寻找php+mysql高手合作
- 怪事:在EditPlus中编辑都是好的,在Eclipse中打开就是乱码(头部会出现一个字符:锘),将文件编码设置为UTF-8,就是好的,但设置成gb23
- 100分求教这个安装apache的小问题!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 没天理啊!我发现了php的bug!!!!
- 招兵买马启示
- workpress 在页面中输出附件信息给用户下载 很急 求大神解答
- input type为复选框的时候,name和value有什么不同?怎么用?
- 急:php中Web打印怎樣去掉 頁眉頁脚?
<?
foreach(){
//不知道是不是需要嵌套循环出
}?>
$fg=explode("|",$getdata1[xx]);
foreach($fg as $g1){
$a = explode("_",$g1);
echo $a[0];
echo $a[1];
}
echo <<<HTML
<table border="1" align="center">
<tr align="center">
<td width="84">姓名</td>
<td width="99">学校</td>
<td width="89">操作</td>
</tr>
HTML;
foreach(explode('_|',$getdata1['xx']) as $one){
if (!empty($one)) echo '<tr align="center"><td>'.str_replace('_','</td><td>',$one)."</td><td>ops</td></tr>\n";
}
echo '</table>';
$get1=mysql_query("select id,xx from per ;");
$getdata1=mysql_fetch_array($get1);
$fg=explode("|",$getdata1[xx]);
$g1=explode("_",$fg);
?>
<table border="1" align="center">
<tr align="center">
<td width="84">姓名</td>
<td width="99">学校</td>
<td width="89">操作</td>
</tr>
<?
$getdata1[xx]="王军_华科大_|军_科_|日日日_又由于_|";
$str=explode('|',$getdata1[xx]);
foreach($str as $key=>$value){
echo '<tr>';
$arr=explode('_',$str[$key]);
foreach($arr as $ak=>$av){
echo '<td>'$av'</td>';
}
echo '</tr>';
}[/color]?>
$getdata1='王军_华科大_|军_科_|日日日_又由于_|';
$table = array('<table border="1" align="center"><tr align="center"><td width="84">姓名</td><td width="99">学校</td><td width="89">操作</td></tr>', '', '</table>');
// 方法一:
$fg=split( "[_|]", $getdata1 );
for($ii=0, $len=count($fg); $ii<$len; $ii+=3)
{
$table[1] .= '<tr align="center"><td>' . $fg[$ii] . '</td><td>' . $fg[$ii+1] . '</td><td>' . $fg[$ii+2] . '</td></tr>';
}
echo join("\r\n", $table);// 方法2
$table[1]='';
$fg= explode( "|", $getdata1 );
foreach($fg as $v){
if(''==$v) continue;
$v = explode("_", $v);
$table[1] .= '<tr align="center"><td>' . $v[0] . '</td><td>' . $v[1] . '</td><td>' . $v[2] . '</td></tr>';
}
echo join("\r\n", $table);
?>
<?
foreach($fg as $key){
$g1=explode("_",$key);
if($g1[0]){
?>
<tr align="center">
<td><?=$g1[0]?></td>
<td><?=$g1[1]?></td>
<td><a href="arr.php?cmd=edit&md5id=<?=$getdata1[id]?>">修改</a></td>
</tr>
<?
}}
?>
<?php
$getdata1='王军_华科大_|军_科_|日日日_又由于_|';
$table = array(' <table border="1" align="center"> <tr align="center"> <td width="84">姓名 </td> <td width="99">学校 </td> <td width="89">操作 </td> </tr>', '', ' </table>');
// 方法一:
$fg=split( "[_|]", $getdata1 );
for($ii=0, $len=count($fg); $ii <$len; $ii+=3)
{
$table[1] .= ' <tr align="center"> <td>' . $fg[$ii] . ' </td> <td>' . $fg[$ii+1] . ' </td> <td>' . $fg[$ii+2] . ' </td> </tr>';
}
echo join("\r\n", $table);// 方法2
$table[1]='';
$fg= explode( "|", $getdata1 );
foreach($fg as $v){
if(''==$v) continue;
$v = explode("_", $v);
$table[1] .= ' <tr align="center"> <td>' . $v[0] . ' </td> <td>' . $v[1] . ' </td> <td>' . $v[2] . ' </td> </tr>';
}
echo join("\r\n", $table);
?>
per:
id ,uid用户表:
uid,name,shcool这样更新就很方便了,直接更新用户表字段,也不用你前面的那些字符串分割操作了