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
https://forums.phpfreaks.com/topic/130935-solved-build-a-table/
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
https://forums.phpfreaks.com/topic/130935-solved-build-a-table/#findComment-679700
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
https://forums.phpfreaks.com/topic/130935-solved-build-a-table/#findComment-679702
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.