Page 1 of 1
Inserting data and retrieving data???
Posted: Tue Oct 10, 2006 5:12 am
by cturner
I am wondering if someone could please tell me how I can insert an article into the items table then insert an articleid into the comments table and retrieve the articleid when viewing the comments for that article with PHP and MySQL? I have been trying to work it out but am getting nowhere. Thanks in advance.
Posted: Tue Oct 10, 2006 7:16 am
by feyd
The basic concept is to use an INSERT query on the items table to produce the articleID for later use. Afterwhich you use your database's facility to retrieve the last primary key id generated and use that as an INSERT query against the comments table.
Pulling out the item is a fairly simple inner join.
Code: Select all
SELECT
*
FROM
itemTable
INNER JOIN
commentTable
ON
commentTable.articleID = itemTable.articleID
WHERE
commentTable.commentID = '2'