MySQL和PHP:仅显示表中的第一个字段

MySQL和PHP:仅显示表中的第一个字段

问题描述:

I am working with PHP and MySQL. I need to retrieve all the rows from the database table and display on the browser in tabular form, but for some reason only the First field in the table gets displayed and others fields don't show up or are not pulled from the database.

Here is my PHP code.

<?php
include("DBConn.php");

$result = mysql_query("SELECT * FROM new_table");

if(!$result) {
  die("Database query failed: " . mysql_error());
}

echo "<table>
<caption>Signal Data:</caption>
<thead>
<tr>
   <th scope=\"col\">TagName:</th>  
  <th scope=\"col\">Enabled</th>  
  <th scope=\"col\">EU Value</th> 
</tr>
</thead>
<tbody>";

while ($row = mysql_fetch_array($result)) {

$tag = $row["TagName"];
$status = $row["Enabled"];
$Ev = $row["EUValue"];

echo "<tr>
 <th scope=\"row\">$tag</th>
 <td>$status</td>
 <td>$EV</td>
   </tr>";
}
echo  "</tbody></table>";
?>

What is wrong with this PHP code? The code itself executes fine without any error.

我正在使用PHP和MySQL。 我需要从数据库表中检索所有行并以表格形式显示在浏览器上,但由于某种原因,只显示表中的第一个字段,而其他字段不显示或未从数据库中提取。 p>

这是我的PHP代码。 p>

 &lt;?php 
include(“DBConn.php”); 
 
 $ result = mysql_query(“SELECT * FROM new_table”); 
 
if(  !$ result){
 die(“数据库查询失败:”。mysql_error()); 
} 
 
echo“&lt; table&gt; 
&lt; caption&gt;信号数据:&lt; / caption&gt; 
&lt; thead&gt;  ; 
&lt; tr&gt; 
&lt; th scope = \“col \”&gt; TagName:&lt; / th&gt; 
&lt; th scope = \“col \”&gt;已启用&lt; / th&gt; 
&lt;  th scope = \“col \”&gt;欧盟值&lt; / th&gt; 
&lt; / tr&gt; 
&lt; / thead&gt; 
&lt; tbody&gt;“; 
 
而($ row = mysql_fetch_array($ result)){  
 
 $ tag = $ row [“TagName”]; 
 $ status = $ row [“Enabled”]; 
 $ Ev = $ row [“EUValue”]; 
 
echo“&lt; tr&gt;  
&lt; th scope = \“row \”&gt; $ tag&lt; / th&gt; 
&lt; td&gt; $ status&lt; / td&gt; 
&lt; td&gt; $ EV&lt; / td&gt; 
&lt; / tr&gt  ;“; 
} 
echo”&lt; / tbody&gt;&lt; / table&gt;“; 
?&gt; 
  code>  pre> 
 
 

此PHP代码有什么问题 ? 代码本身执行正常,没有任何错误。 p> div>

The third row can be corrected by matching the case of the variable names. You are assigning the value to a variable named $Ev (lowercase 'v'):

$Ev = $row["EUValue"];

but attempting to use a variable named $EV (uppercase 'V'):

<td>$EV</td>

For both the second and third fields, ensure that Enabled and EUValue exactly match the names of the fields in your database, including case and spelling.

Finally, check the data itself to ensure that the fields have data in your database, and that the data is displayable in your HTML output.