簡體   English   中英

一個表可以在php while循環中運行嗎?

[英]Can a table run in a php while loop?

我試圖創建一個通過查詢不斷從數據庫中提取數據的表,但是當我將它放入需要不斷獲取數據的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';
} 

編輯:這是我的查詢

$result = mysql_query("SELECT * FROM p4updates WHERE DB4PrimeKey = 4");

// Fetch live values from data base
while($row = mysql_fetch_array($result))
    {
    $str1npos = $row['str1npos'];$str1spos = $row['str1spos'];$str2npos = $row['str2npos'];$str2spos = $row['str2spos'];$str3npos = $row['str3npos'];
    $str3spos = $row['str3spos'];$str4npos = $row['str4npos'];$str4spos = $row['str4spos']; $str5npos = $row['str5npos'];
    $str5spos = $row['str5spos'];$str6npos = $row['str6npos'];$str6spos = $row['str6spos'];$str7npos = $row['str7npos'];
    $str7spos = $row['str7spos'];$wrnpos = $row['wrnpos'];$wrspos = $row['wrspos'];

    $strout1 = $row['strout1'];$strout2 = $row['strout2'];$strout3 = $row['strout3'];$strout4 = $row['strout4'];$strout5 = $row['strout5'];
    $strout6 = $row['strout6'];$strout7 = $row['strout7'];$wrout4 = $row['wrout4'];

    $strfbk1 = $row['strfbk1'];$strfbk2 = $row['strfbk2'];$strfbk3 = $row['strfbk3'];$strfbk4 = $row['strfbk4'];$strfbk5 = $row['strfbk5'];
    $strfbk6 = $row['strfbk6'];$strfbk7 = $row['strfbk7'];$wrfbk3 = $row['wrfbk3'];

    $stralm1 = $row['stralm1'];$stralm2 = $row['stralm2'];$stralm3 = $row['stralm3'];$stralm4 = $row['stralm4'];$stralm5 = $row['stralm5'];


    }

CSS

.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; }

HTML

  <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“”。 $ diff1 = row ['diff1']。''。 $ direction1 = row ['direction1']。 “”;

嘗試:echo“”。 $ diff1 = $ row ['diff1']。''。 $ direction1 = $ row ['direction1']。 “”;

您在while循環中的每個echo語句中的$ row []前面都缺少$

在循環內嘗試一下。 (我假設您的表中包含具有這些特定名稱的行。如果沒有,則刪除$row['direction']然后讓您的循環抓取每個變量。)

編輯:我刪除了變量定義,因為它覆蓋並重新定義了上面的操作。 據我$diff$diff變量不是來自您上面的數據庫,而是從數據庫中的其他變量中計算得出的。 假設這些計算正確,並且沒有錯誤,請嘗試以下操作(使用上面提供的示例)。 注意,如果變量不是來自row則不想使用行。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM