Marinus
Marinus

Reputation: 441

Displaying data from database in table

I am trying to display data in table form with 3 columns. Each should have a main category with some drop down lists. I get all the information to display but all is in one column and the drop down information does not display with the correct heading.

echo "<table>";

while ($row = mysql_fetch_array($result)) {
    $count = 1;

    if ($count = 1) {
        $sCatID = ($row['CatID']);
        echo "<tr valign='top'><td><b><a href='#" . $sCatID . "'>" . $sCatID . "</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 "</td>";
        }
        $count = 2;
    } elseif ($count = 2) {

        $sCatID = ($row['CatID']);
        echo "<td><b><a href='.$sCatID.'>" . $sCatID . "</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='#'>" . $row2['Sub'] . "</a><br>";
            echo "</td>";
        }
        $count = 3;
    } elseif ($count = 3) {

        $sCatID = ($row['CatID']);
        echo "<td><b><a href='.$sCatID.'>" . $sCatID . "</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.'>" . $sSub . "</a><br>";
            echo "</td></tr>";
        }

        $count = 1;
    }
}
if ($count = 2) {
    echo "<td>&nbsp;</td><td>&nbsp;</td></tr>";
} elseif ($count = 3) {
    echo "<td>&nbsp;</td></tr>";
}
echo "</table>";

It doesn't seem to close the rows and table correctly... And it is also putting some of the drop down items before it displays the first heading.

If i display it in only one column it is working fine.

Upvotes: 0

Views: 474

Answers (1)

saji89
saji89

Reputation: 2251

You should use == instead of single = in your if statements. Else it would execute everytime as that condition is always true.

Upvotes: 1

Related Questions