Coding By Instinct
I love it when you don't know how to code something, so, before you cheat and use Google, you try what your instinct tells you ought to work and, low and behold, it does.
This doesn't happen with Notes as much as it does when I'm learning some other "new" technology. To me it's a sign of how good that technology is. If things work in a way that makes sense then it can't be bad.
It happens quite a lot with Flex, which I find very intuitive, but yesterday it happened with MySQL. Here's what happened:
I have a SQL table, called Hitlog, that records every hit on a document -- what time it was opened and by what user. It looks lie this:
What I needed to do was find out not only how many times a document had been read but also by how many people.
From the table above we can see that the document with the ID beginning in 857 has been read 7 times. Not by 7 different people though. Only 4 people have read it. Deandre read it 4 times herself. Maybe she's the author and is trying to make it appear more popular!?
What I needed to do was display on the document itself the following text:
This document has been read 7 times, by 4 different people.
I knew this was possible. I just wasn't sure how.
What's The SQL
It's simple to get the total number of reads, using SQL, like so:
SELECT count(*) FROM hitlog WHERE DocID="8574F37... ...04B0B3C"
This would simply return 7.
It's also simple to get a list of the people who've read it:
SELECT DISTINCT Username FROM hitlog WHERE DocID="8574F37... ...04B0B3C"
Which would return four rows -- one for each person.
What I wanted was a count of the number of these rows though. Also, what I really wanted to do was get both numbers returned from a single SQL statement.
What I didn't know you could do and what I tried as an intuitive solution was the following:
SELECT count(*), count(DISTINCT Username) FROM hitlog WHERE DocID="8574F37... ...04B0B3C"
Et voila, it worked and I got that warm fuzzy feeling you get when you work something out yourself.
Haha, I know what you mean.
One thing that gets me every now and again (maybe it's just me... not sure!) is when I'm trying to do something quite complicated that I sort of understand but can't seemingly get my head around. I start typing and I'm sort of sure what I'm coding will do the job but I don't really know why, and I have to read back what I typed to myself to understand what's going on.
I agree. I've got a project going for a friend, selling supp's online. Some of the things we're doing I haven't done before b/c I've done mostly intranet designs, and I'm really enjoying the accomplishments of progress in a new sense.
It feels good doesn't it!?
I _wish_ code worked out like this for me more often. :P
how i wish notes have SQL statements rather than build views or formulas like that when selecting documents hehe.