Jump to content

[SOLVED] Foreign Key


camdenite

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.