Inserting data and retrieving data???
Moderator: General Moderators
Inserting data and retrieving data???
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.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.
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'