0

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.

4

1 回答 1

1

您应该在 if 语句中使用==而不是 single =。否则它将每次都执行,因为该条件始终为真。

于 2012-05-21T10:41:49.273 回答