Re: Posting a variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2007-04-11 at 21:30 -0500, Richard Lynch wrote:
> On Wed, April 11, 2007 8:17 pm, Robert Cummings wrote:
> > I'd rather lose track of $row['foozie'] than $row[1]. Either way, if
> > your code is structured well, the row data should be in close
> > proximity
> > to it's use. At the very least, if your field names are informative
> > instead of 'foozie', maybe 'email' then I think you'll have less
> > trouble
> > remembering. This isn't really a religious issue... it's a clarity
> > issue. I mean, why bother naming variables if you think you might get
> > confused later. Just call your vars $foo1 to $fooX-- at least that's
> > the
> > path you've laid out as an argument.
> 
> But I don't USE row[1]!
> 
> And certainly not $foozie!  I would have hoped that was obvious, but I
> guess not. :-(

*hehe* I saw where the rest of your post went, but the initial part
walked down this path ;)

> I use $email and I have it "close" enough to the source query, and
> with the name matching up (for simple columns) or very clear and
> descriptive names for calculated SQL values.
> 
> I might do an aggregate count(*) with a group by and it's going to be
> called $count, if it's simple enough a script to remember what is
> being counted, since there is only one thing being counted.
> 
> If I have both venues and cities being counted, it's $venue_count and
> $city_count.
> 
> I don't really like carrying around the "baggage" of
> $row['venue_count'] everywhere, especially if I'll use the variable a
> lot.
> 
> If I'm going to assign it to a well-named variable in 3 lines anyway,
> wny do I need it to be in an assoc array?  I don't.

The table fields should have been named well enough in the first place.
If you don't want the baggage or you're using the variable so much that
it warrants an elimination of array access overhead then why not use the
more concise extract()?

<?php

    extract( mysql_fetch_assoc() )

?>

Yes, yes, I know some idiot out there will clobber their vars *lol* --
or not clobber their vars as necessary *grin*. Either way, list()'ing
out all the fields you've already declared in the query (or that are
implied) or directly pulling out to a var using assignment is just code
in two places that could be in one.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux