Jump to content

[SOLVED] Build a table


The Little Guy

Recommended Posts

I'M stumped...

 

My SQL returns all the info I need, the correct way I want it, and it's output would look something like this:

 

category

order

title

1

 

0

 

This is 1

 

 

1

 

2

 

This is 2

 

 

 

2

   

0

   

This is 1

 

   

   

2

   

1

   

This is 2

   

 

When I do my loop, I need each category in it's own table.

So... both category 1 rows need to be in one table

and both category 2 rows need to be in a second table.

 

both tables will look exactly the same, but some tables may have one row and others can have more

Link to comment
Share on other sites

while($row = mysql_fetch_array($sql)){
    echo '<table class="mainTable">';
    echo'<tr>
            <th class="categoryTitle" colspan="2">'.$row['category'].'</th>
            <th>Topics</th>
            <th>Posts</th>
        </tr>';
        echo'<tr>
            <td class="boardUpdate">
                <img src="" />
            </td>
            <td class="boardTitle">
                <p><a class="bold" href="board.php?id='.$row['bid'].'">'.$row['title'].'</a>
                <p>'.$row['description'].'</p>
            </td>
            <td class="boardTopics">
                <p>'.$row['topicCount'].'</p>
            </td>
            <td class="boardPosts">
                <p>'.$row['postCount'].'</p>
            </td>
            <td class="boardLastInfo">
                <p>Last Post Info</p>
            </td>
        </tr>';
    echo '</table>';
}

 

The current Result: http://dudeel.com/forums/

 

The first two should be in one table, the next three in a second table and the last one should be by its self.

Link to comment
Share on other sites

$prevCat = null;
while($row = mysql_fetch_array($sql))
{
    if($prevCat != $row['category'])
    {
        echo '<table class="mainTable">';
        echo'<tr>
            <th class="categoryTitle" colspan="2">'.$row['category'].'</th>
            <th>Topics</th>
            <th>Posts</th>
        </tr>';

        $prevCat = $row['category'];
    }

        echo'<tr>
            <td class="boardUpdate">
                <img src="" />
            </td>
            <td class="boardTitle">
                <p><a class="bold" href="board.php?id='.$row['bid'].'">'.$row['title'].'</a>
                <p>'.$row['description'].'</p>
            </td>
            <td class="boardTopics">
                <p>'.$row['topicCount'].'</p>
            </td>
            <td class="boardPosts">
                <p>'.$row['postCount'].'</p>
            </td>
            <td class="boardLastInfo">
                <p>Last Post Info</p>
            </td>
        </tr>';

    if($prevCat != $row['category'])
    {
        echo '</table>';
    }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.