MYSQL TABLES (One To Many Relationship)
| From: | abdulazeez alugo | Date: | Sun, 22 Mar 2009 16:04:09 +0000 |
| Subject: | MYSQL TABLES (One To Many Relationship) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-290534@lists.php.net to get a copy of this message | ||
Hi guys,
I need help on something I'm working on and its really eating me up so I'll appreciate any
help I can get on it.
I'm writing code for a site that posts a topic for discussion and accepts comments (Just like a
parliament).
There are different discussions for every day and the comments should be displayed along with the
corresponding topics per day.
Now I wrote the code below but dont know if I'm right. (I created two tables in my database and
to create a relationship between the tables, I put the id field for the topics into the comments
table):
<?php
function getpost_comments()
{
global $conn; //This gets the database started (already defined)
$result= mysql_query("SELECT * FROM Pcomments, Parliaments WHERE
Pcomments.pcomment_id=Parliaments.parliament_id");
if (!$result) print mysql_error();
else {
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
print "$row[name] - $row[comment]<br/>\n";
}
}
}
?>
I know some of you will probably think its a stupid question but I'm going with the school of
thought that says the only stupid question is the one that's not asked.
Thanks in anticipation of your positive responses.
Alugo Abdulazeez
www.frangeovic.com.
_________________________________________________________________
Show them the way! Add maps and directions to your party invites.
http://www.microsoft.com/windows/windowslive/products/events.aspx