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.

6
  • Not sure for what you mean Radu, all I know its is not working the way I would like it to. Somehow the loop is not working correctly and Sorry! but i don't know why... Commented May 21, 2012 at 9:16
  • Your if statements should be using == rather than = as using a single = will reassign the value rather than compare against it Commented May 21, 2012 at 9:17
  • I have tried that lethalmango, but now it displays the numbers of the CATID rather than the value. Commented May 21, 2012 at 9:45
  • Are you trying to display the same data into three different table columns? what's the point? Commented May 21, 2012 at 9:59
  • I Have decided to create a table for each of the categories with it own sub headings. It works fine so I have removed the the $count=2 and $count=3 completely. Thanks anyway for anyone that had a look at it. More than one way to do something I guess. Commented May 21, 2012 at 10:22

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.