PHP DOM method gotcha!

July 2nd, 2009

Ok, so here is a “gotcha” with PHP’s DOM… if you use the method createTextNode(), and the string you pass happens to have HTML chars, the method will AUTOMATICALLY convert to html special chars. Guess they should call the method createTEXTnode instead!

Chris Fontes Programming

MySQL and a NULL index walk into a bar….

June 9th, 2009

Did you know that in MySQL, if you have a NULL field in your “unique” index, you can have multiple duplicates of that row and MySQL will turn a blind eye? Oh yes, that is a pain. Example: If you have a unique index that consists of 2 fields (ID and secondID), you “could” end up with (1, NULL), (1, NULL), (1,NULL). Sure, it looks to be identical, but all 2 identical rows can exists in perfect harmony. This is particularly problematic when realying on a unique key and using INSERT ON DUPLICATE KEY UPDATE queries.

Trust me. 3 days of frustration to learn this. MySQL does NOT classify this as a bug, but the community has made it clear that it acts like one. Hopefully they will fix this in an upcomnig release.

Chris Fontes Programming

Following your own advice

June 2nd, 2009

Well I have been pulling my hair out trying to debug a Javascript issue, and it turns out that not only do I know the solution, but I JUST blogged about it! You see, in Javascript, an empty string will return false in an if statement, so:

val=”";

if (val){ …

will return false. Although it shouldn’t, because it IS technically a value (the value of nothing). SO, using a !== fixes this, as earlier in the code I explicitly set it to false, then change it to a value if I need. Long story short,

if (val !== false){ …..

is what I should have done in the first place!

Chris Fontes Programming

New Testament Prophecy

June 2nd, 2009

So, I was in a healthy debate with my brother on this. He feels that modern day prohecy is simply speaking the Word of God (the Bible), and not containing any prediction, as there is no new revelation.

I, on the other hand, feel that prophecy, being a gift of the Holy Spirit, is something more. While I will agree that there will be no new revalation, God may give you a word to pass on to another, just like in the old testament. If prophecy was just professing the word of God, how is that a gift? Can’t anyone (saved or not) read the words aloud and be a “prophet”? Maybe I am just splitting hairs. I am pressed for time, so I have no scripture to back up my point at the moment, but please feel free to comment and leave scripture to back it up.

Chris Fontes Christianity, Family

Purchasing a home makes my eye twitch

June 2nd, 2009

So, we are in the process of buying our first home! Yeah! While I am excited about reaching the next stage in life, the entire process makes me stress out. If you know me, that is a big deal… I am usually calm, relaxed and full of fun (and food). But for some reason, buying a house literally makes my eye twitch. It has been twitching for almost two months now, and I am ready to poke it out with a pen.

On the brighter side, I can’t wait to have a home that my kids can grow up in and remember as their own. Praise God for the opporunity He has given us!

Chris Fontes Family, Other

PHP functions that return Boolean

June 2nd, 2009

OK, so there are several function in PHP that return Boolena true or false. So, if you want to test against them, us coders get in the habit of doing something like this:

if (!isarray($myArray)){ …..

Problem. What is that function returns an interger, OR boolen, such as strpos? You will see tons of people doing this:

if (!strpos($haystack, $needle)){ ……

Bad bad bad. This will cause all kinds of problems. What if the “needle” is found at position Zero? Zero is also interpereted as False, although in this case what you want is a True… SOOO… be good boys and girls and use the mysterious triple equals.

if (stripos($needle, $haystack) === false){ ….

or

if (stripos($needle, $haystack) !== false){ ….

You can also use a greater than -1, but I see this as sloppy. Is it actaully sloppy? Maybe not, just my feelings on the matter. I feel that if you should be as specific as you can get in your logical expression testing.
Hope that helps ya!



Chris Fontes Programming

PHP array key’s and the period (dot) character

March 31st, 2009

I found today that you cannot have a period in your string key. For example, this is invalid:

$array['my.name'] = “some name”;

This is most important to note when you are posting (or getting for that matter) into a script. I found this out while attempting to Post data from an AJAX call to my server. PHP automatically turns periods (dots) into underscores. Check out the reference below, it took me FOREVER to find supporting material to this theory…

http://php.net/manual/en/language.variables.external.php#language.variables.external.dot-in-names

Happy coding

Chris Fontes Programming

LOL and ROFL

March 30th, 2009

So, when you type lol or rotfl are you actually? You should be. Otherwise you are a liar. That is all, continue your lying, IM liar.

Chris Fontes Other

Preparation, direction and common sense

March 28th, 2009

OK, so this post is all about the importance of the aforementioned title. Whether you are a first timer or a seasoned veteran, creating a new website is a huge task. Just like home renovation, a new site will take longer than you want, be more involved that you imagined and cost more than you had hoped.

Also just like home renovation, preparation is vital. If you don’t do your homework, and allow PLENTY of time for the research and planning stages, buy the time you start developing the stitching will fall out of the design. I cannot stress this enough… starting to develop a site without an ENTIRE scope and direction is foolish and unprofessional. I’m just sayin’….. :)

Chris Fontes Programming

MySQL Conditional Left Joins

March 27th, 2009

Ok,  so the title is a bit misleading… I am not going to show you necessarily how to only LEFT JOIN a table based on a condition, but I will show you how to get the same results as you would expect.

First, you may be asking…. why would I ever need to? Well, let ’s say you have 3 tables. Table One is acting as your primary index relation table. Then, based on the info IN that table, you need to join either table Two or table Three. How would you do it?

SELECT `one`.first_name, `one`.male_female,
IF(`one`.male_female=’boy’,boyTable.meaning,girlTable.meaning) AS name_meaning
FROM `one`
LEFT JOIN `two` AS boyTable ON boyTable.first_name=`one`.first_name
LEFT JOIN `three` AS girlTable ON girlTable.first_name=`one`.first_name

This will let you, for example, select the meaning of someones name if the meanings where in two different tables based on gender. This is of course, is just an example, and this particular situation would be handled better by just setting a flag in a singular table that specifies male of female, but I needed to come up with some way illustrate the concept, so her you are!

hope this helps someone

Chris Fontes Programming , , ,