What i am looking for is , how do i insert data for only that topic , like , on my home page , in recent topics section , i have to display number of reviews of that topic only .
What i thought is , to take that topic's id and insert . But i do not know how to do that .
This is my 1st table for Topics.
Expand|Select|Wrap|Line Numbers
- Topic_Id - 1 , 2 , 3
- Title - First Topic , Second Topic , Third Topic
- Category_ID - 3 , 1 , 1
- Date - yyyy-mm-dd
Expand|Select|Wrap|Line Numbers
- Category_ID - 1 , 2 , 3
- Category_name - PHP , MYSQL , PDO
Expand|Select|Wrap|Line Numbers
- try
- {
- $query = $conn->prepare("INSERT INTO `topics` (title,category_id) VALUES (:title,:category_id)");
- $query->execute(array(
- 'title' => $_POST['title'],
- 'category_id' => $_POST['category_id'],
- ));
- }
- catch (PDOException $e)
- {
- error_log($e->getMessage());
- die($e->getMessage());
- }
Expand|Select|Wrap|Line Numbers
- $sql = "SELECT * FROM review ORDER by pid DESC limit 0,3";
- $q = $conn->query($sql);
- $q->setFetchMode(PDO::FETCH_ASSOC);
- while($row = $q->fetch()){
- echo $row['title'];
- echo $row['username'];
- }
Expand|Select|Wrap|Line Numbers
- Topic_ID -
- Rating -
- Review -
- User_ID -
Problem 2 : And is there a need of user-id in 1st table because there is also an option for user to insert topics ?
Problem 3 : How do i select number of reviews for a particular topic to display next to it on home page ?