Advertisement
Ortund

Forum Home

Dec 1st, 2011
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. // $dbh = PDO connection to database
  2.  
  3. // Idea: Similar forum design to http://eu.battle.net/wow/en/forum/
  4.  
  5. <table>
  6. <?php
  7.     $sql = 'SELECT * FROM titles';
  8.     $result = $dbh->prepare($sql);
  9.     $i = 2;
  10.     $even = 1;
  11.     foreach ($result->query($sql) as $row) {
  12.         echo '<tr>'.
  13.             '<td colspan="2">'.$row['TitleName'].'</td>'.
  14.             '</tr>';
  15.  
  16.         $sql2 = 'SELECT * FROM categories WHERE TitleID = '.$row['TitleID'];
  17.         $result2 = $dbh->prepare($sql2);
  18.         foreach ($result2->query($sql2) {
  19.             if (@i % 2 === 0) { // @i is a multiple of 2, so create a new row
  20.                 echo '<tr>';
  21.             }
  22.             else {
  23.                 $even = 0;
  24.             }
  25.  
  26.             echo '<td>'.
  27.                 '<a class="cat_title">'.$row2['CategoryTitle'].'</a><br />'.
  28.                 '<span class="cat_sum">'.$row2['CategorySummary'].'</span>'.
  29.                 '</td>';
  30.             if ($even == 1) { // $i is a multiple of 2, close the row
  31.                 echo '</tr>';
  32.             }
  33.             $i = $i++;
  34.         }
  35.     }
  36. ?>
  37. </table>
  38.  
  39. // This code should ideally build a table that looks similar to the following:
  40. // |=======================|
  41. // |Title1                 |
  42. // |=======================|
  43. // |CAT1       |CAT2       |
  44. // |category1  |category2  |
  45. // |=======================|
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement