Jakes Mumbles...

Hey Everybody!

First of all, I'd like to thank you for taking the time to come and check me out. I've been doing things online since about 1998 and my passion is webdev (PHP/MySQL).

My thinking is minimalist and I want to share with you my own experiences with my own projects and also my thoughts on how to get your product or service out there to market. Also, how to finish the damn project you've been sitting on for so long.

If you take anything away from this, please do yourself a favor and take whatever idea you have right now that you've been putting off -- whether it because of details not all being there or not -- and get to doing it. Write up a few screens in html and start mapping out your interface...

You'll thank me later..

Cheers
Jake

PHP: When to use arrays and when not to…

The general rule of thumb is that if you are pulling in a lot of data at once, it’d be better to use something other than arrays.  Arrays are great for data manipulation before it gets rendered into a view.  You can sort it, walk it to check for certain values, etc.  This comes at a cost though: Memory. 

So how do I handle large amounts of data?  PHP has built in funcitons like mysql_fetch_assoc and mysql_fetch_array that will pull in one record at a time.  It may look something like this:

while($row = mysql_fetch_array($query)) {
// output or whatever here.
}

The drawback here is that you can only manipulate the row currently assigned to the $row var, unfortunately.  However, it uses far less memory to output.

My rule of thumb is if I have more than say 20-50 records on the page, I’ll use something other than an array to handle that.   No reason to push all that data into an array, just to output it (do nothing special to it).