Duplicating the result when adding two tables

Mia_Wyoming

New Member
I'm working on a website with categories. When the user clicks a link it goes to \[code\]categories.php?id=$id\[/code\]This is working. Since I'm using FK, I have to use this code:\[code\]$result = mysql_query( "SELECT * FROM post_posts, post_cat WHERE post_cat = $id" )or die("SELECT Error: ".mysql_error());$num_rows = mysql_num_rows($result);if ($result) { while ($row = mysql_fetch_array($result)) { $_SESSION['idpost_posts']=$row['idpost_posts']; echo '<div id="single-post" class="slidingDiv"> <div id="title">' . $row['post_header'] . '</div> <div id="image"><img src="' . $row['post_thumb'] . '" width="300" height="200"></div> <div id="text">' . substr($row['post_content'], 0, 500) . '<a href="http://stackoverflow.com/questions/15842545/page.php?id=' . $row['idpost_posts'] . '"> Les mer...</a>' . ' </div> <div id="author">' . "Skrevet: " . date('j. F Y ', strtotime($row['post_date'])) . ' | <a href="http://stackoverflow.com/questions/15842545/user.php?id=' . $row['idpost_users'] . '">' . $row['user_name'] . '</a></div> <div id="post-divider"></div> </div>'; } }\[/code\]The code is working, but as I stated earlier, it shows the same row 5 times. Any idea how to fix this?EDIT:THis is what i'm using now, and it shows only two rows now, which is better:\[code\]$result = mysql_query( "SELECT DISTINCT idpost_posts, post_content, post_header, post_thumb, post_date, idpost_users, user_name FROM post_posts, post_cat, post_users WHERE post_cat = $id" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result);if ($result) {while ($row = mysql_fetch_array($result)) { $_SESSION['idpost_posts']=$row['idpost_posts']; echo '<div id="single-post" class="slidingDiv"> <div id="title">' . $row['post_header'] . '</div> <div id="image"><img src="' . $row['post_thumb'] . '" width="300" height="200"></div> <div id="text">' . substr($row['post_content'], 0, 500) . '<a href="http://stackoverflow.com/questions/15842545/page.php?id=' . $row['idpost_posts'] . '"> Les mer...</a>' . ' </div> <div id="author">' . "Skrevet: " . date('j. F Y ', strtotime($row['post_date'])) . ' | <a href="http://stackoverflow.com/questions/15842545/user.php?id=' . $row['idpost_users'] . '">' . $row['user_name'] . '</a></div> <div id="post-divider"></div> </div>';\[/code\]
 
Back
Top