lacey Posted November 27, 2013 Share Posted November 27, 2013 I'm trying to view the posts stored in the database but for some weird reason I am only seeing the messahe thats says the post cannot be accessed. Can someone look at the code below and see if you can point out where i have gone wrong please. <?phpinclude 'connect.php';include 'header.php';echo "<div class='inside'>";echo '<h3>Category View</h3><br />'; //retrieve the category from the database based on $_GET['cat_id']$sql = "SELECT cat_name, cat_description FROM category WHERE cat_id = " . $_GET['id'];$result = mysql_query($sql) or die("<p>Could not execute query. Sorry for the inconvenience, please try again later.</p>"); if($result){ if(mysql_num_rows($result) == 0) { echo '<p>There are no topics in this category yet.</p>'; } else { $row = mysql_fetch_assoc($result); echo '<table width="100%" class="category"> <tbody> <tr> <th colspan="2" class="tableheader">' . $row['cat_name'] . '</th> </tr> <tr> <th class="leftpanel">Topic</th> <th class="rightpanel" align="center">Last Post</th> </tr>'; $sql = "SELECT topic_id, topic_subject, topic_date, topic_cat FROM topic WHERE topic_cat = " . mysql_real_escape_string($_GET['id']) ." ORDER BY topic_date DESC"; $result = mysql_query($sql,$connect) or die('The topics could not be displayed, please try again later.<br /><br />'); if(mysql_num_rows($result) == 0) { echo 'There are no topics in this category yet.'; } else { //prepare the table while($row = mysql_fetch_assoc($result)) { $sql = "SELECT post_id, post_date, post_by FROM post WHERE post_topic = " . $row['topic_id'] ." ORDER BY post_date DESC LIMIT 1"; $result2 = mysql_query($sql,$connect) or die('The post could not be accessed, please try again later.<br /><br />'); $row2 = mysql_fetch_assoc($result2); echo '<tr>'; echo '<td class="leftpart">' .'<h4><a href="topic.php?id=' . $row['topic_id'] . '">' . $row['topic_subject'] . '</a><br /><h4>' .'</td>' .'<td class="rightpart">' .'<span class="byline"><span class="created">' .istoday($row2['post_date']) .'</span><br/><span class="floatright">by ' . $row2['post_by'] .'</span></span></td>'; echo '</tr>'; } } echo '</tbody> </table>'; }} echo "</div>";include 'footer.php';?> Quote Link to comment Share on other sites More sharing options...
B_CooperA Posted November 27, 2013 Share Posted November 27, 2013 (edited) nvm Edited November 27, 2013 by B_CooperA Quote Link to comment Share on other sites More sharing options...
Solution xProteuSx Posted November 27, 2013 Solution Share Posted November 27, 2013 What error do you get as output? You've got some error checking code in there, but you don't specify it to help us out. I suggest that you take a look at the MySQL query itself. As you've got it it is: $sql = "SELECT cat_name, cat_description FROM category WHERE cat_id = " . $_GET['id']; I think that might be the problem. Try something like this: $sql = " SELECT cat_name, cat_description FROM categoryWHERE cat_id = $_GET[id]"; I think the issue might have been your use of " and ' within the query. Hope this helps. Cheers! Quote Link to comment Share on other sites More sharing options...
xProteuSx Posted November 27, 2013 Share Posted November 27, 2013 Just realized another thing. You said that the result was based on $_GET['cat_id'] but you were using $_GET['id'] in your query ... Quote Link to comment Share on other sites More sharing options...
lacey Posted November 27, 2013 Author Share Posted November 27, 2013 thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.