T_VARIABLE解析错误检索结果

时间:2011-12-09 10:29:31

标签: php mysql database

我已经在这方面工作了一段时间并整理了整个后端,我只是在与mySQL数据库挣扎,因为这是我第一次在项目中使用它! 我试图从数据库中回忆一些信息,但是从2个不同的表中回忆并显示它。 我正在尝试在循环中调用信息时收到T_VARIABLE错误。

<p><?php

$inttotalcredits=0;

$result = mysql_query("SELECT * FROM site_products");
$set = mysql_fetch_array($result)
$prod_id = $row[0]

echo "<table border='0' width='100%'>
<tr>
<th>Product ID</th>
<th>Part Name</th>
<th>Part Number</th>
<th>Description</th>
<th>Level</th>
</tr>";

while($row = mysql_fetch_array($result)
{

echo "<tr>";
echo "<td>" . "<center> $row[0] </center>" . "</td>";
echo "<td>" . "<center> $row[1] </center>" . "</td>";
echo "<td>" . "<center> $row[2] </center>" . "</td>";
echo "<td>" . "<center> $row[4] </center>" . "</td>";
}

$result1 = mysql_query("SELECT * FROM site_trans WHERE trans_product = $prod_id");
while($row1 = mysql_fetch_array($result1))
{
echo "<td>" . "<center> $row1[6] </center>" . "</td>";
$inttotalcredits += $row1[6];
echo "</tr>";
echo "</center>";
}
echo "<td>" . "" . "</td>";
echo "<td>" . "" . "</td>";
echo "<td>" . "<b>Total Stock Items</b>" . "</td>";
echo "<td>" . "<b><center> $inttotalcredits </center></b>" . "</td>";

echo "</table>";

?></p>

我不知道这是一个直接的错误我或者我只是没有正确构建循环。

奥利弗

1 个答案:

答案 0 :(得分:4)

您遗失的;

$set = mysql_fetch_array($result)
$prod_id = $row[0]

应该是:

$set = mysql_fetch_array($result);
$prod_id = $row[0];

同样如Lyth所指出的,你在while语句中缺少parethesis:

while ($row = mysql_fetch_array($result)

应该是:

while ($row = mysql_fetch_array($result))

我建议重写代码,不要在PHP代码中回显HTML元素:

<p>
<table border='0' width='100%'>
   <tr>
      <th>Product ID</th>
      <th>Part Name</th>
      <th>Part Number</th>
      <th>Description</th>
      <th>Level</th>
   </tr>

<?php
$inttotalcredits = 0;

$result = mysql_query("SELECT * FROM site_products");
$set = mysql_fetch_array($result)
$prod_id = $row[0]

while($row = mysql_fetch_array($result)) :
?>
<tr>
   <td><center><?php echo $row[0] ?></center></td>
   <td><center><?php echo $row[1] ?></center></td>;
   <td><center><?php echo $row[2] ?></center></td>
   <td><center><?php echo $row[3] ?></center></td>
<?php endwhile ?>

依此类推...它更干净,更容易调试。