0

少し助けが必要です。配列をテーブルに変換するループは非常にうまく機能しますが、結果に多くの余分な情報が追加されます。

Facebook Graph APIから友達を表示するテーブルを作成するループです。

<? 

sort($friends_data['data']);
    echo "<tr>"; 
    foreach ($friends_data['data'] as $friend)
    {
    $names = substr($friend['name'],0,1);

        if ($names == 'M') {
             echo "<td><ul><a href='https://www.facebook.com/".$friend['id']."' target='_blank'>".$friend['name']."</a></ul></td>"; 
            }

      if (($current_col++)%$cols == 0){
        echo "</tr><tr>";
      }
    }
   while (($current_col++)%$cols !=0){
   echo "<td>&nbsp;</td>";
   }
   echo "</tr>"; 
?>

これが吐き出すものです(友達は削除されました):

<table border="0" cellpadding="4" cellspacing="10" width="100%" ><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr><td>&nbsp;</td></tr></table>
4

1 に答える 1

1

あなたはそれがあなたなしで あなたに空を与えるとき、あなたは<td/>その場合のために何も扱いませんでした($names != 'M')<tr>td<td>($names == 'M')

これを試して

<? 

sort($friends_data['data']);
    echo "<tr>"; 
    foreach ($friends_data['data'] as $friend)
    {
    $names = substr($friend['name'],0,1);

        if ($names == 'M') {
             echo "<td><ul><a href='https://www.facebook.com/".$friend['id']."' target='_blank'>".$friend['name']."</a></ul></td>"; 
            }
        else
        {
             //this of $name is not 'M'
             //assume empty if $name is not 'M'
             echo "<td>&nbsp;</td>";
         }

      if (($current_col++)%$cols == 0){
        echo "</tr><tr>";
      }
    }
   while (($current_col++)%$cols !=0){
   echo "<td>&nbsp;</td>";
   }
   echo "</tr>"; 
?>

または、表示したい場合は$names == 'M'

<? 

sort($friends_data['data']);
    echo "<tr>"; 
    foreach ($friends_data['data'] as $friend)
    {
    $names = substr($friend['name'],0,1);

        if ($names == 'M') {
             echo "<td><ul><a href='https://www.facebook.com/".$friend['id']."' target='_blank'>".$friend['name']."</a></ul></td>"; 
            if (($current_col++)%$cols == 0){
                echo "</tr><tr>";
            }
        }              
    }
   while (($current_col++)%$cols !=0){
   echo "<td>&nbsp;</td>";
   }
   echo "</tr>"; 
?>
于 2012-05-17T17:09:36.613 に答える