Storing Compressed Data in a MySQL Database

January 7th, 2006


PHP Lesson

May 1st, 2005

I feel so proud. My first post that isn’t a rant. Now, those who deem my blog worthy of their limited surf time will get a brief lesson in PHP that should minimize your code a bit.

Now, normally we use something like this for ifs:

if ($variable == 'Hello') {

right? Now what if we have lots of variables?

if ($variable == 'Hello' && $variable2 == 'Hello' && $variable3 == 'Hello' && $variable4 == 'Hello' && $variable5 == 'Hello') {

There is an easier way, and it minimizes if sizes.

$variable1 = 'Hello'; // These would be set already
$variable2 = 'Hello';
$variable3 = 'Hello';
$variable4 = 'Hello';
$variable5 = 'Hello';

$varray = array($variable1,
$variable2,
$variable3,
$variable4,
$variable5);

$val = array_fill(0, 5, 'Hello');
if ($varray == $val) {
echo 'Equal';
}

Tada, easy.

As suggested by a commenter, I am also including an example where this technique could be useful in practice.


$varray = array($_POST[’user’],
$_POST[’pass’],
$_POST[’verpass’],
$_POST[’email’],
$_POST[’name’]);

$val = array_fill(0, 5, NULL);
if ($varray != $val) {
// Execute code for form processing
} else {
// Display error
}

This would check if any of the form elements were empty, saving the need for large if conditional statements.

Note: this is outdated. Better methods are easy to come by, just check the comments below.


No, I won’t write your script

April 27th, 2005

Programming around the internet is considered the “cool” thing to do. Everyone wants to do it, especially those wishing to establish a presence on the internet, unfortunately for us true coders, we are plagued by those who would have us code it for them and they to take the credit. This problem seems especially rampant on CodingForums.com, where daily the PHP forum gets posts such as:

…”you see i don’t want to make it because i am not very good at php unless it involves forms or reading and writing files. Anyone know where i could locate such a program and if not could someone please make one for me?”

Note that this user did not ask for an example to get started. He did not post that he could not find what he was looking for on Google. No, he asked someone to find one for him, or make one for him. Make one for him, not an example. I find myself wishing to click a nice, shiney ban button, preferably polished and ready for use.

I once coded an in depth example for one person (which worked flawlessly), and he replied back that he was getting errors. He posted the code and it appeared he had mauled the code implementing it into a page, took off my comment, and changed a few variable names (forgetting many). Once again, I find myself wishing for the shiney ban button.

Another person bids for jobs, then asks for help coding the project he receives. Yet another demanded we provide him with examples or he would contact the “FIB” for not following the “fredom of infomation thing”. Besides a ban button, I find myself wanting a brick.


PHP

April 21st, 2005

Many people on the CodingForums.com programming forum help people. These are the people like me, who give their time daily to help n00bs on their programming projects, and sometimes even code entire samples for them. Unless the person is genuinely stumped, and has attempted to fix their problem/create, or simply to better their knowledge they are n00bs in my eyes.

II. Defining ‘Noob’

Contrary to the belief of many, a noob/n00b and a newbie/newb are not the same thing. Newbs are those who are new to some task* and are very beginner at it, possibly a little overconfident about it, but they are willing to learn and fix their errors to move out of that stage. Noobs, on the other hand, know little and have no will to learn any more. They expect people to do the work for them and then expect to get praised about it, and make up a unique species of their own. It is the latter we will study in this guide so that the reader is prepared to encounter them in the wild if needed.

Besides the reasons above, they ask some of the most moronic questions I have seen to date. To illustrate this fact, I have posted a cartoon.

PHP Heal
Credit: joe-ks.com for original cartoon.