1

我只是不知道为什么我收到错误消息,我尝试删除''和()

我在 phpmyadmin 中运行了脚本,它说我的语法问题出在 $result = ("SELECT * FROM 'test_prefixCatagory' ORDER by 'Cat'");

$result = ("SELECT * FROM 'test_prefixCatagory' ORDER by 'Cat'");


while($row = mysql_fetch_array($result))

$sCat = ($row['Cat']);
$sCatID = ($row['CatID']);
{
echo "<table>";
 echo "<tr valign='top'><td><b><a href='#".$sCat."'>".$sCat."</a></b><br>";
 // column 1 categories
 $result2 = ("SELECT * FROM `test_prefixSubCat` WHERE `CatID`=$sCatID");
 // sub-cats
 while($row2 = mysql_fetch_array($result2)) 
    {
  $sSub = ($row2['CatID']);
  $sSubID = ($row2['SubID']);
  echo "<dd><a href='#'>".$sSub."</a><br>";

 }

 echo "<br></td></tr>";
echo "</table>";
 }

有人有想法吗?

4

3 回答 3

1

试试这个 :

<?php
$result = mysql_query("SELECT * FROM `test_prefixCatagory ORDER by `Cat`");

while ($row = mysql_fetch_array($result)) {
$sCat = $row['Cat'];
$sCatID = $row['CatID'];
echo "<table>";
echo "<tr valign='top'><td><b><a href='#" . $sCat . "'>" . $sCat . "</a></b><br>";
// column 1 categories
$result2 = mysql_query("SELECT * FROM `test_prefixSubCat` WHERE `CatID`='".$sCatID. "'");
// sub-cats
while ($row2 = mysql_fetch_array($result2)) {
    $sSub = $row2['CatID'];
    $sSubID = $row2['SubID'];
    echo "<dd><a href='#'>" . $sSub . "</a><br>";

    }

        echo "<br></td></tr>";
        echo "</table>";
}
?>
于 2012-05-17T13:48:42.737 回答
0
$result = ("SELECT * FROM `test_prefixCatagory` ORDER by `Cat`");
于 2012-05-17T13:49:26.887 回答
0

您不仅需要添加mysql_query,还需要从表名和字段名中删除单引号。如果您愿意,可以使用反引号,但不能在表名周围使用单引号

$result = mysql_query("SELECT * FROM `test_prefixCatagory` ORDER by `Cat`");

// other query:
 $result2 = mysql_query("SELECT * FROM `test_prefixSubCat` WHERE `CatID`=$sCatID");

调试 MySQL 问题时,使用mysql_error()来查看问题描述。

于 2012-05-17T14:07:35.123 回答