· 6 years ago · Mar 05, 2019, 08:14 AM
1comment text from blog url
2------------------------------------------
3first comment text first-blog-url
4second comment text first-blog-url
5third comment text first-blog-url
6fourth comment text blog-2-url
7fifth comment text blog-2-url
8sixth comment text 3rd-blog-url
9
10//I read a comment from the comments file, `comment text` and `from blog url`
11
12//does a blog exist that has 'link' that matches 'from blog url'
13$blog = //SELECT FROM blogs where 'link' has value 'first-blog-url'
14
15//if it doesn't exist, create it
16if($blog == null){
17 $blog = INSERT INTO blogs a new record and set 'link' to 'first-blog-url'
18}
19
20//then read the id of the (existing or just-created) blog row
21$blog_id = $blog->getId();
22
23//then use the $blog_id to insert the comment into the 'comments' table.
24
25//does this comment text already exist for this blog id?
26$comment = SELECT FROM comments where `commenttext' has value 'whatever comment text' and 'blogid' has value $blog_id
27
28//if it doesn't exist, create it
29if($comment == null){
30 $comment = INSERT INTO comments a new record and set 'commenttext' to 'the comment text' and 'blogid' to $blog_id.
31}
32
33$comment_id = $comment->getId();
34
35blogs:
36
37id link other fields
38--------------------------------------------
391 first-blog-url
402 blog-2-url
413 3rd-blog-url
42
43comments:
44
45id commenttext blogid
46-----------------------------
471 random 1
482 comment 1
493 goes 1
504 here 2
515 any 2
526 thing 3
53
54INSERT INTO blogs (link)
55select 'first-blog-url'
56from dual
57where not exists
58( select 1
59 from blogs
60 where link = 'first-blog-url'
61);