我正在尝试制作一张表:
简而言之,与普通表完全相反。
此外,水平扩展数据的顶部会有一个标题,解决方案X(X表示actaul列的数量,图片使所有内容都清晰)。
我添加了一张图片,该图片应该足够清晰,我会尝试使用指南。!
图片:
执行此操作的代码是:
<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>
我被困住了,因为你看到发生的事情是下一个&#39; sql行&#39;获取的内容始终显示在第一个下方。我想要的是每一个接下来的SQL行&#39;必须在下一个解决方案编号<#39;。
之下如果你能帮我解决这个问题,我会非常感激。如果您需要更多详细信息,请随时询问:)。
答案 0 :(得分: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>