[thelist] functionitis

Emma Jane Hogbin emmajane at xtrinsic.com
Thu Apr 3 11:44:43 CST 2003

On Thu, Apr 03, 2003 at 12:39:30PM -0500, Beam wrote:
> A rule of thumb I've heard, and often ignored, is: 2x2 - if it is more than 2 
> lines or you are going to use it more than twice, make it reusable

Interesting rule...I think I agree with the concept of it, but I might
make the numbers a little bigger than 2x2. 4x4 maybe?

> If you are going to have a lot of results, you could eat up a lot of memory 
> with this technique Doing what you need to do with the resultset inside the 
> while() loop is generally the best practice.

Usually less than 20 rows with 10 fields. I figure I'm pretty safe with that. :) It's
always a toss up if I should put results into PHP arrays or if I should do
a new call to the database. With this limited number of results playing
with PHP arrays should be faster than new calls to the db.

> that said, you could do:
> 	while ($rows = mysql_fetch_array($mysql_query)) {
>  		foreach ($rows as $k=>$v) {
> 			if ($k == 'id') continue;
> 			$results[$rows["id"]][$k] = $v;
> 	        }
>  	}

Of course! Thanks. :)


Emma Jane Hogbin
[[ 416 417 2868 ][ www.xtrinsic.com ]]

More information about the thelist mailing list