camdenite Posted February 4, 2009 Share Posted February 4, 2009 Hi all, I am trying to get the information of the foreign key in one table that is held in another. Tables blogb and blog_category. I tried this: $query = "SELECT blog_id, date2, heading, title FROM blogb, blog_category"; //$query = "SELECT CONCAT(pid, ', <br>', pname, ', <br>', pcontent, ', ', ptitle, '. <br /><br />') AS pages FROM tbl_pages"; $result = @mysql_query ($query); // Run the query. $num = mysql_num_rows($result); if ($num > 0) { // If it ran OK, display the records. echo "<p>There are currntly $num Blog entries.</p>\n"; // Table header. echo '<table align="center" cellspacing="0" cellpadding="5"> <tr> <td align="left"><b>Category</b></td> <td align="left"><b>Date</b></td> <td align="left"><b>Title</b></td> <td align="view"><b>View</b></td> <td align="left"><b>Edit</b></td> <td align="left"><b>Delete</b></td> </tr> '; // Fetch and print all the records. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo '<tr> <td align="left">' . $row['title'] . '</td> <td align="left">' . $row['date2'] . '</a></td> <td align="left"><a href="blog_view.php?id=' . $row['blog_id'] . '">' . $row['heading'] . '</td> <td align="left"><a href="blog_view.php?id=' . $row['blog_id'] . '">View</a></td> <td align="left"><a href="blog_edit4b.php?id=' . $row['blog_id'] . '">Edit</a></td> <td align="left"><a href="delete_blog.php?id=' . $row['blog_id'] . '">Delete</a></td> </tr> '; } But this just gives me the same blog displayed multiple times becase it has more than one category. I suppose I want the blog displayed once and the various categories displayed in a categories section. How would I write this? Associate one blog with many categories? Thank you for any advice, Colin Link to comment https://forums.phpfreaks.com/topic/143844-solved-foreign-key/ Share on other sites More sharing options...
camdenite Posted February 4, 2009 Author Share Posted February 4, 2009 // Make the query. $query = "SELECT blog_id, date2, heading, category_id, id, title FROM blogb, blog_category WHERE category_id = id "; Link to comment https://forums.phpfreaks.com/topic/143844-solved-foreign-key/#findComment-754798 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.