php - Is a query-inside-query to display categories like this possible? -
function getforums($id) { $currenthost = "http://$_server[http_host]"; $query = "select * categories"; try { global $db; $stmt = $db->prepare($query); $stmt->execute(); $result = $stmt->fetchall(); foreach($result $row) { $category_title = $row['category_title']; $category_id = $row['category_id']; echo '<div class="forum pleft"> <div class="forum-header"> <span class="header-text">'.$category_title.'</span> </div> <table>'; $query2 = "select * forums category_id='".$category_id."'"; try { global $db; $stmt2 = $db->prepare($query2); $stmt2->execute(); $result2 = $stmt2->fetchall(); foreach($result2 $row2) { $forum_cat_id = $row2['category_id']; $forum_id = $row2['forum_id']; $forum_title = $row2['forum_title']; $forum_topic_count = $row2['forum_topic_count']; $forum_post_count = $row2['forum_post_count']; $forum_last_topic_id = $row2['forum_last_topic_id']; $forum_last_topic = $row2['forum_last_topic']; $forum_last_date = $row2['forum_last_date']; $forum_last_user = $row2['forum_last_user']; $fixed_last_topic = substr($forum_last_topic,0,25).'...'; echo '<tr> <td class="title"><a href="'.$currenthost.'/forums/view-forum/index.php?cid='.$forum_cat_id.'&fid='.$forum_id.'">'.$forum_title.'</a></td> <td class="topics">'.$forum_topic_count.'</td> <td class="posts">'.$forum_post_count.'</td> <td class="lastpost"><a href="'.$currenthost.'/forums/view-thread/index.php?cid='.$id.'&fid='.$forum_id.'&tid='.forum_last_topic_id.'">'.$fixed_last_topic.'</a> <a href="'.$currenthost.'/users/index.php?username='.$forum_last_user.'">'.$forum_last_user.'</a> @ '.$forum_last_date.'</td> </tr> </table> </div>'; } } } // getting error here! } catch(pdoexception $ex) { die("error"); } }
i marked in code i'm getting error, 7 lines up. had question never got answered , i'm trying make forums of subcategories (forums) go category , don't make whole new forum div each time.
you haven't written catch second try. code end error waiting catch. change code way
} catch(pdoexception $ex) { die("error"); } } // getting error here!
Comments
Post a Comment