Marinus
Marinus

Reputation: 441

SQL ERROR mysql_fetch_array(): not valid?

I just can't figure out why i get the error message, I have tried removing the'' and the()

I have run the script in phpmyadmin and it says the problem with my syntax is at $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>";
 }

Do anyone have an idea?

Upvotes: 1

Views: 114

Answers (3)

d4rkpr1nc3
d4rkpr1nc3

Reputation: 1827

Try this :

<?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>";
}
?>

Upvotes: 1

MrCode
MrCode

Reputation: 64526

Not only do you need to add mysql_query but you also need to remove the single quotes from the table name and field name. You can use backticks if you wish but not single quotes around table names.

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

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

When debugging MySQL problems, use mysql_error() to see a description of the problem.

Upvotes: 0

triclosan
triclosan

Reputation: 5714

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

Upvotes: 0

Related Questions