Official Killer Media Corporate Website (Click to View)

Using MySQL’s rand() Statement

October 24th, 2007

So, recently I’ve been working very hard on a TGP system of sorts…as you may already know. Well, I was trying everything to figure out how to get the listings in a MySQL database to “re-position” themselves, or using a better term, “rotate”. And, I did it! This was actually extremely simple compared to a lot of other techniques I was trying out to tackle the problem. And what a solution it is!

MySQL has an embedded command to use for randomly selecting a row(s) from the database, straight from the command line. It was this wonderful command that saved me many hours, if not days, of development and tinkering time. I LOVE YOU rand()!! Here is the just of my discoveries:

Basic syntax:

SELECT column FROM table
ORDER BY RAND()

Now, I’m not going to just give out gimmies here so you’ll have to use your own brain and figure out how to use the rand() command to produce a ranking system! Enjoy!

Southern California Is Burning Down!!!

October 24th, 2007

If you haven’t heard about all of the fires in California by now then you’re just blind, can’t smell and can’t hear as well! Most are suspected arson. The following is a bit of data and info that I’ve gathered about the fires, I’ll try and keep this updated:

Community Little Book has put together a nice list of resource links about the various fires.
Fox11 LIVE News Coverage.
NASA images of the many fires in Southern California.
Google’s Interactive fire map.
The Department of Forestry and Fire Protection

Latest Statistics:
500,000+ People Evacuated.
1,300 Homes Lost.
10 People Dead.
640 Square Miles Burned.
50,000 San Diego Residents Returned Home.

Hello PHP Version 6!

August 12th, 2007

So it finally came to my attention that the “hackers” over at The PHP Group are back at it again. PHP version 6 is in full production swing and looks as though to be heading down the path of least resistance when it comes to when it will be ready to use professionally. Now, if you know me you know how much I’m in love with PHP and can fully realize how excited I am about this. So, I’ve decided to chat a bit about what they’ve done so far and plan to do with the upcoming release of PHP version 6.

Goodbye <%
I was wondering even why they implemented this funny Microsoft-style tag in the first place. ASP-style tags have been removed from PHP as of version 6!

Goodbye Register Globals
One of the largest security holes PHP has ever had will now finally say farewell. Register Globals will no longer be an ini file setting, and if found will raise an E_CORE_ERROR flag, directing you to the documentation where they explain why it’s “bad”. This means that all scripts written which utilize “Global Arrays” will brake indefinitely and the developers will have no choice but to either ditch them entirely or re-code them the right way.

Goodbye Register Long Arrays
Gone are the days when you can utilize something like $sess_vars = $HTTP_SESSION_VARS; You must now use, and only use, non-global variables. $HTTP_SESSION_VARS will now be simply $_SESSION. This goes the same for all the rest of the super global arrays.

Goodbye Magic Quotes
Another one of PHP’s largest security holes is saying goodbye in PHP6, and like Register Globals, will raise an E_CORE_ERROR flag if found. This means the use of the following functions is now deprecated: magic_quotes, magic_quotes_sybase and magic_quotes_gpc.

Goodbye Safe Mode
The magical and almost mystical “PHP Is Safe” setting is being removed, because by its use it implies that it makes PHP “safe”, when in fact it does not.

Hello Mr. Visibility Keyword public
With Objects (see PHP - OOP) the visibility keyword var has been given a helping hand. The visibility keywords public, private, and protected have been completely implemented and now you won’t get an E_ERROR when using var. While you can still use the keyword var in classes and methods, it will be redundant as it means exactly the same thing now as the keyword public. Bottom line: no more E_ERROR when using var instead of public and they both are the same now.

These are just a few of the many changes and improvements the PHP Group has done with the future version of PHP. I will with no doubt post a lot more about the future release of PHP in the near future so stay tuned.

To download the most unstable release of PHP6 visit PHP Snapshots.

PHP Tip: Using the Ternary Operator

August 12th, 2007

A ternary operator is an operator that takes three arguments in total. Two actual arguments and one result. The arguments and result can be of different types.
Many programming languages that use C-like syntax feature a ternary operator, (?:); unqualified, “ternary operator” usually refers to this. The (?:) operator is used as a shorthand replacement for the if-then-else conditional statement; the general form is condition ? op1 : op2. If condition is true, the statement evaluates as op1; otherwise, it evaluates as op2.

(Source.) Text in italics has been amended by Benjamin Eskew.

In PHP the above quote holds true for ternary operators and is very useful with many purposes and you should learn to use it religiously if you are not already. Here’s a few reasons why to use it so you know you won’t be wasting your time with this article:
Using the ternary operator will speed up the execution time of your code, reduce server memory/bandwidth usage/over-usage, and makes your code easier to read. On with the show…

You should be quite familiar with the following if-then-else statement:

if(expression){
     $var = “true value”;
}else{
     $var = “false value”;
}

There’s a much easier and more elegant way to go about this:

$var = (expression) ? “true value” : “false value”;

Example:

$var = true;
$return_value = ($var == true) ? “The variable is true.” : “The variable is false.”;
echo $return_value; // prints: The variable is true. to the browser window.