表能否在php while循环中运行?

表能否在php while循环中运行?,php,html,Php,Html,我试图创建一个表,该表通过查询不断地从数据库中提取数据,但当我将表放入需要不断获取数据的while循环中时,我无法让它显示任何内容。我只是对我的代码做了一些错误的事情,还是这不可能?我将发布css和html 编辑2:这是对变量(如$diff)的计算 $str5npos = ($str5npos /100); $str5npos = $str5npos +12.015; $str5nposgraph = (($str5npos/40) *100); $str5spos = ($str5spos

我试图创建一个表,该表通过查询不断地从数据库中提取数据,但当我将表放入需要不断获取数据的while循环中时,我无法让它显示任何内容。我只是对我的代码做了一些错误的事情,还是这不可能?我将发布css和html 编辑2:这是对变量(如$diff)的计算

$str5npos = ($str5npos /100);
$str5npos = $str5npos +12.015;
$str5nposgraph = (($str5npos/40) *100);

$str5spos = ($str5spos /100);
$str5spos = $str5spos +12.015;
$str5sposgraph = (($str5spos/40) *100);
$total5= round($str5npos + $str5spos); 

$diff5 = round($str5npos - $str5spos);
$direction5 = 'North';
if ($diff5 < 0) {
    $direction5 = 'South';
} 
CSS

HTML


是: “回声”$diff1=行['diff1'].'$方向1=行['direction1']。"" ;

尝试: “回声”$diff1=$row['diff1'].'$方向1=$row['direction1']。"" ;


在while循环中的每个echo语句中,$行[]前面的$都丢失了

请在循环中尝试此操作。(我假设您的表中有具有这些特定名称的行。如果没有,请删除像so
$row['direction']
这样的数字,并让您的循环获取每个变量。)

编辑:我删除了变量定义,因为它覆盖并重新定义了上面的操作。据我所见,
$diff
变量不是来自上面的数据库,而是从数据库中的其他变量计算出来的。假设这些都是正确计算的,并且该部分没有错误,请尝试下面的方法(使用上面提供的示例)。注意,如果变量不是来自某一行,则不希望使用

echo '<td height ="54" align="center">' . $diff5.' '. $direction5. '</td>' ;
echo“”$"五"$方向5.';

Hi,AJAX将是你的朋友。为什么不:
echo“{$row['diff1']}{$row['direction1']}”是否有理由在单引号和双引号之间交替使用?我知道您正在使用单引号来区分HTML变量,但随后您会跳回HTML变量的单引号。在HTMLNote中,我坚持使用单引号表示文本字符串,双引号表示变量。您最大的问题是没有正确分配
$row[]
变量。我的眼睛。你应该清理一下…谢谢你的建议,我得到了同样的结果,但是这是一个非常窄的绿色条,它是表格的背景色,但是没有内容。谢谢你的建议,我看到这样做的好处,但我仍然只得到一个没有文本的小绿色行,屏幕上只有一小条,这是表格的背景色。请显示您的查询。我有一种感觉,问题就出在你上面展示的内容上,我没有看到任何行名称
diff1
等等,这些行的工作并不完美,但我按照你的建议以类似的格式慢慢地添加了一些内容,这似乎完成了trickI始终发现自己解决问题是最好的:)很高兴你得到了它
.MainTable { float: left;width:100%;  background-color:#CEF7CE;border-collapse:collapse;  font-size: 20px; }
.MainTable th { background-color:#197D19;color:white; font-size: 15px; }
.MainTable td, .MainTable th {  padding:1px;border:1px solid #000; font-size: 20px; }
  <col width="10%">
  <col width="9%">
  <col width="9%">
  <col width="9%">
  <col width="9%">
  <col width="9%">
  <col width="9%">
  <col width="9%">
  <col width="9%">


<tr>    


<?php
while($row = mysql_fetch_array($result))
{   
// Row one Entrys 

echo "<td height ='54' align='center'>" . $diff1= row['diff1'].''. $direction1 = row['direction1']. "</td>" ;
echo "<td height ='54' align='center'>" . $diff2 = row['diff2'] .''.$direction2 = row['direction2']. "</td>";
echo "<td height ='54' align='center'>" . $diff3= row['diff3'] .''.$direction3= row['direction3'] . "</td>"; 
echo "<td height ='54' align='center'>" . $wrdiff= row['wrdiff'] .''.$wrdirection= row['wrdirection'] . "</td>"; 
echo "<td height ='54' align='center'>" . $diff4= row['diff4'].''. $direction4= row['direction4'] . "</td>";
echo "<td height ='54' align='center'>" . $diff5= row['diff5'] .''.$direction5= row['direction5']  ."</td>"; 
echo "<td height ='54' align='center'>" . $diff6= row['diff6'] .''.$direction6= row['direction6'] ."</td>"; 
echo "<td height ='54' align='center'>" . $diff7= row['diff7'].''. $direction7= row['direction7'] .  "</td>"; 
}
?>
</tr>   
<!-- Row two Entrys --> 
<tr> <?php
while($row = mysql_fetch_array($result))
{   

echo "<td height ='54' align='center'>" .$strout1= row['strout1'] .'%'."</td>";
echo "<td height ='54' align='center'>" . $strout2= row['strout2']. '%'."</td>";
echo "<td height ='54' align='center'>"  .$strout3= row['strout3'] .'%'."</td>";
echo "<td height ='54' align='center'>" . $wrout4= row['wrout4']. '%'."</td>";
echo "<td height ='54' align='center'>" .$strout4= row['strout4'] .'%'."</td>";
echo "<td height ='54' align='center'>" . $strout5= row['strout5'] .'%'."</td>";
echo "<td height ='54' align='center'>"  .$strout6= row['strout6']. '%'."</td>";
echo "<td height ='54' align='center'>"  .$strout7= row['strout7'] .'%'."</td>";
} ?>
</tr>
<!-- Row three Entrys -->
<tr><?php
while($row = mysql_fetch_array($result))
{   
echo "<td height ='54' align='center'>". $strfbk1= row['strfbk1']. '%'."</td>";
echo "<td height ='54' align='center'>" . $strfbk2= row['strfbk2']. '%'."</td>";
echo "<td height ='54' align='center'>" . $strfbk3= row['strfbk3']. '%'."</td>";
echo "<td height ='54' align='center'>" . $wrfbk3= row['wrfbk3']. '%'."</td>";
echo "<td height ='54' align='center'>". $strfbk4= row['strfbk4'] .'%'."</td>";
echo "<td height ='54' align='center'>" . $strfbk5= row['strfbk5']. '%'."</td>";
echo "<td height ='54' align='center'>" . $strfbk6= row['strfbk6']. '%'."</td>";
echo "<td height ='54' align='center'>" . $strfbk7= row['strfbk7']. '%'."</td>";
} ?> 
</tr>
<!--  Row four Entrys -->
<tr><?php
while($row = mysql_fetch_array($result))
{   

echo "<td height ='54' align='center'>". $stralm1= row['stralm1']. '%'."</td>";
echo "<td height ='54' align='center'>" . $stralm2= row['stralm2'] .'%'."</td>";
echo "<td height ='54' align='center'>" . $stralm3= row['stralm3']. '%'."</td>";
echo "<td height ='54' align='center'>" . '---'."</td>";
echo "<td height ='54' align='center'>". $stralm4= row['stralm4'] .'%'."</td>";
echo "<td height ='54' align='center'>" . $stralm5= row['stralm5'] .'%'."</td>";
echo "<td height ='54' align='center'>" . '---'."</td>";
echo "<td height ='54' align='center'>" . '---'."</td>";
}
?> 
</tr>

</tr>
</table>
echo '<td height ="54" align="center">' . $diff5.' '. $direction5. '</td>' ;