0

次のテーブルを作成しようとしています。

  • 左側の列名。
  • データを縦に。
  • 次の SQL 行で垂直ではなく水平に展開します。

要するに、通常のテーブルとは正反対です。

また、横方向に展開されたデータの上部には、Solution X (X は実際の列の番号、写真ですべてが明確になります) という名前のヘッダーが付きます。

私が達成しようとしていることを十分に明確にするための写真をガイドラインとともに追加しました.!

画像:

これを行っているコードは次のとおりです。

<table border="1">
  <tr>
    <th></th>
    <th>Solution 1</th>
    <th>Solution 2</th>
    <th>Solution 3</th>
  </tr>
  <?
 while($result = mysql_fetch_array( $data )) 
 { ?>
  <tr>
    <td>SHIPPINGLINE</td>
    <th><? echo $result["SHIPPINGLINE"]; ?></th>
  </tr>
  <tr>
    <td>POL</td>
    <th><? echo $result["POL"]; ?></th>
  </tr>
  <?
 } 

 //This counts the number or results - and if there wasn't any it gives them a little     message explaining that 
 $anymatches=mysql_num_rows($data); 
 if ($anymatches == 0) 
 { 
 echo "Sorry, but we can not find an entry to match your query.<br><br>"; 
 } 

 //And we remind them what they searched for 
 echo "<b>Searched For:</b> " .$findone. " and " .$findtwo;
 } 
 ?>
    </table>

何が起こっているかを見ると、フェッチされる次の「SQL行」が常に最初の行の下に表示されるため、私は立ち往生しています。私が望むのは、次の各「SQL行」が次の「ソリューション番号」の下にある必要があるということです。

これについて私を助けていただければ幸いです。詳細が必要な場合は、お気軽にお問い合わせください:)。

4

1 に答える 1

0
<?php
$output = array();
$c=1;
while($result = mysql_fetch_array( $data )) 
{
  $output[$c]['shippingline'] = $result['shippingline'];
  $output[$c]['pol'] = $result['pol'];
      $c++;
}
?>
<table border="1">
<tr>
<th></th>
<?php
foreach ($output as $key => $html)
{
echo "<th>Solution ".$key."</th>";
}
?>
</tr>
<tr>
    <td>Shipping Line</td>
<?php
foreach ($output as $key => $html)
{
echo "<td>".$html['shippingline']."</td>";
}
?>
</tr>
<tr>
    <td>POL</td>
<?php
foreach ($output as $key => $html)
{
echo "<td>".$html['pol']."</td>";
}
?>
</tr>   
</table>
于 2013-02-27T11:04:55.790 に答える