Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // $dbh = PDO connection to database
- // Idea: Similar forum design to http://eu.battle.net/wow/en/forum/
- <table>
- <?php
- $sql = 'SELECT * FROM titles';
- $result = $dbh->prepare($sql);
- $i = 2;
- $even = 1;
- foreach ($result->query($sql) as $row) {
- echo '<tr>'.
- '<td colspan="2">'.$row['TitleName'].'</td>'.
- '</tr>';
- $sql2 = 'SELECT * FROM categories WHERE TitleID = '.$row['TitleID'];
- $result2 = $dbh->prepare($sql2);
- foreach ($result2->query($sql2) {
- if (@i % 2 === 0) { // @i is a multiple of 2, so create a new row
- echo '<tr>';
- }
- else {
- $even = 0;
- }
- echo '<td>'.
- '<a class="cat_title">'.$row2['CategoryTitle'].'</a><br />'.
- '<span class="cat_sum">'.$row2['CategorySummary'].'</span>'.
- '</td>';
- if ($even == 1) { // $i is a multiple of 2, close the row
- echo '</tr>';
- }
- $i = $i++;
- }
- }
- ?>
- </table>
- // This code should ideally build a table that looks similar to the following:
- // |=======================|
- // |Title1 |
- // |=======================|
- // |CAT1 |CAT2 |
- // |category1 |category2 |
- // |=======================|
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement