diff options
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 45 |
1 files changed, 22 insertions, 23 deletions
@@ -4,7 +4,7 @@ <head> <title>cflip.net forum</title> </head> -<body style="width: 720px;margin: auto;"> +<body> <?php include_once 'templates/header.php'; ?> <h2>Welcome to the cflip.net forum!</h2> <p> @@ -24,35 +24,34 @@ </tr> <?php include_once 'includes/db_inc.php'; + include_once 'model/Category.php'; - $sql = "SELECT * FROM categories"; - $result = mysqli_query($dbc, $sql); - - if (!$result) { - die('Error trying to display posts: ' . mysqli_error($dbc)); + // TODO: The get_all_categories function should return them in the right order + function cmp($a, $b) { + if ($a->id == $b->id) { + return 0; + } + return ($a->id < $b->id) ? -1 : 1; } - if (mysqli_num_rows($result) == 0) { - echo 'No categories found!'; - } else { - while ($row = mysqli_fetch_assoc($result)) { - echo ' <tr> - <td> - <b><a href="category/' . $row['cat_id'] . '">' . $row['cat_name'] . '</a></b> - <br> - ' . $row['cat_description'] . ' - </td> - <td>' . $row['cat_thread_count'] . '</td> - <td>' . $row['cat_post_count'] . '</td> - <td><b>my supercool thread</b><br><small>by <b>cflip</b>, 3 days ago</small></td> - </tr> -'; - } + $categories = get_all_categories($dbc); + usort($categories, "cmp"); + + foreach ($categories as $category) { + echo '<tr>'; + echo '<td>'; + echo '<b><a href="category/' . $category->id . '">' . $category->name . '</a></b>'; + echo '<br>' . $category->description; + echo '</td>'; + echo '<td>' . $category->thread_count . '</td>'; + echo '<td>' . $category->post_count . '</td>'; + echo '<td><b>my supercool thread</b><br><small>by <b>cflip</b>, 3 days ago</small></td>'; + echo '</tr>'; } ?> </table> <h2>More from the forum</h2> - <table width="100%"> + <table> <tr> <th>Recent Posts</th> <th>Recent Threads</th> |