从数据库读出
$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>

解决方案 »

  1.   


    <?
    foreach(){
    //不知道是不是需要嵌套循环出
    }?>
      

  2.   


    $fg=explode("|",$getdata1[xx]);
    foreach($fg as $g1){
        $a = explode("_",$g1);
        echo $a[0];
        echo $a[1];
    }
      

  3.   

    $getdata1=array('xx'=>'王军_华科大_|军_科_|日日日_又由于_|');
    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>';
      

  4.   


    $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]?>
      

  5.   

    <?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);
    ?>
      

  6.   


    <?
    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>
    <?
    }}
    ?>  
      

  7.   


    <?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);
    ?>
      

  8.   

    字符串截取 ! 可以实现,来晚一步 分给人抢了! 还是说一下方法吧 explode()方法变成数组! 然后用数组的每隔KEY 指定属性! 在用一个循环 ECHO出!
      

  9.   

    你可以做两个表,一个per表,一个用户表
    per:
    id ,uid用户表:
    uid,name,shcool这样更新就很方便了,直接更新用户表字段,也不用你前面的那些字符串分割操作了
      

  10.   

    现在的表结构就是分开放的,例如个人教育经历,工作经历与个人信息分为3个表,问题是在做查询时,慢,查不到要查的key值,所以现在把所有的数据放一个表中就避免了跨表查询的效率问题。如果按现在这个以分割的方式,怎么做