music: Spirit Thing
book: where wizards stay up late
So I thought this would be a good time to explain the back end of the website. Not the php side, but the sql. Since you can't get a computer science degree without being inundated with databases, I tacked this problem like we did at A&M. I first started off with a rough ER Diagram.
If you've never heard of an ER Diagram, it's basically just something that shows you have information is connected. In the past, databases were hierarchtical. Now that we use relations, we have to show what data goes where and how it is all inner connected.
As you can see from the diagram, this went through much work
. I setup all the tables I thought I would need. The two tables in the center are simply there to show how posts relate to the tags and comments. I later completely removed HasComments because there was no need for it (since a comment can only be applied to one post, that information can be stored in the comment entry without any problem).
Tags had the most work done to it (why it took so long to implement). It originally had only three fields (ID, Name, Desc). After some thought, I removed ID since the name of the tag should be unique. Sadly, doing comparisons with a user defined tag name proved to be very difficult so I placed ID back in. Desc was the field for description.
, I felt so stupid when I did my first few queries and got SQL syntax errors. If you don't have much knowledge of SQL, DESC is a reserved word for sorting (you can sort in descending order). So I renamed it to Details. I also added NumOfPosts to the tags. This is just to keep from having to pull all the tag's posts every time it's displayed.
Getting the tag information for a post, or the posts that the tag relates to was fun to write. It's a two stage query:
| SQL: getTaggedPosts |
| select * from Posts WHERE ID IN( select PostID AS ID from IsTagged WHERE TagID = 'TagID#') ORDER BY ID DESC |
As you can see, I first make a query of all the PostID's from the IsTagged table, then select from the Posts table the IDs that match. I saw online someone complaining about subqueries not working for him (actually, he was complaining about a logical error in mySQL). His problem was that the IN clauses didn't match. But, you can see that with AS, you can make a field with a different name and get the query to execute properly.
I guess that's pretty much all for now, maybe I'll make my first tutorial on how to setup a database with MySQL and php... nah! 
Tags: WAD(5) FollowerofJC.com(10)









.
(yeah, I've also updated the emoticon library)! It now searches posts, projects, about me, and comments! But that's not what makes it super... it also highlights the keywords in the searched items and directs the page to the queried element (thanks to moo.fx.scroll)! It's pretty slick to watch! Also, the searches are Boolean, so you can type something like: 