Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's the story with $result ?

Status
Not open for further replies.

JustKIDn

MIS
May 6, 2002
386
US
Hi all,

Just quickly, why does everyone use $result ?

As Seinfeld would say 'Not that there's anything wrong with that!'

I've just been noticing that almost every example that requests data from a DB uses $result.

I've checked, it's not a reserved word or variable. So apparently it's not required to only use $result.

So just a quick poll:
[ul][li] 1. Are we just unimaginative? (is that a word?)[/li]
[li] 2. It's easy to read/understand?[/li]
[li] 3. Or did the grandfathers of PHP start a fad that hasn't gone out of style yet?[/li]
[/ul]
I was just wondering, because it doesn't seem to be as common (consistantly) in other languages.

[ponder]

tgus

____________________________
Families can be together forever...
 
I dont know about anyone else but I have 2 main reasons.
1. I was taught to use varibale names that describe what information that varibale holds. $result seems to be a good name for holding the DB query results.
2. I learnt php by using the php manual. They use $result in their examples and I have never thought of a better name for it (I guess I am unimaginative :))
 
uhm.. lol, i never noticed that, but now that i think about it, i use $result a lot.. don't know why, maybe because i always used it and most examples of code and snippets use it... as Westbury said, what better name to give a variable that holds the result of a query ? :p

jamesp0tter,
jamespotter@netcabo.pt

p.s.: sorry for my (sometimes) bad english :p
 
I think it's great that there is such consistancy with so many programmers in one particular language.

The reason for my question, is that I was going to write a script that had multiple queries. And I started looking at other examples to see what other variable names were used by others. That's when I noticed that $result is almost always used.
That made me start looking to see if it's a reserved word, with special purpose or something. (it's not!)

Although $result is very discriptive and makes sense to use it. It seems to be common practice to use something like $sql or $str_sql (also discriptive) in other languages that use sql select statments.

I'm not trying to change anything! I was really trying to verify to myself that it's alright to use other names also.

[hammer] [hammer] [hammer]

Thanks!

tgus

____________________________
Families can be together forever...
 
I prefer to call my results $applesack, and sql queries $toefungus... ;-)

I'm the same way:
Code:
$result=mysql_query($sql);
while ($row=mysql_fetch_assoc($result)) {
...
}
$result, $row, and $sql seem to hard-coded into my brain. Oh, and yes, I also put in the if mysql_num_rows($result) check too, but it didn't really fit mood ;-)

----
JBR
 
The only time I ever use $result is when I'm sending a friend a snippet of code to explain what I'm talking about. $result is the new $x.

Otherwise, I usually use some variation on $result, for the same reason as you, tgus - that I have multiple results. I like to keep "result" in the name, though, just to keep it distinguished from all of the other kinds of variables I'm working with.

E.G.:
<code>

//find all open entries from foo
$selectOpenFooSQL = &quot;select foo_id from foo where open = 1&quot;;

//the result of that
$selectOpenFooResult = mysql_query($selectOpenFooSQL) or die(mysql_error());
</code>

It's verbose, but crystal clear for those times when you need to go back six months later and figure out what the heck you were thinking.
 
It's a meaningful name, being the result of a query... I often use different variables as well, so long as they describe what the variable is... If I'm selecing the all the users, I am apt to use
Code:
$users
, but if it's more complicated like all users with 10 or more posts who haven't been on for five days or more and eat grapes, then
Code:
$results
is a lot better than
Code:
$userswithtenpostsnotonfivedayseatgrapes
, unless your insaine.
 
Not only that (all of above) but if I have a query to get a bunch of stuff, then iterate thru it in a for loop or whatever, and need a subquery inside the loop (say extract something from person table that wouldn't have nicely fit with a join in outer query, I'll use $resultp, $rowsp for 'result-person' and rows-person in this result.
It CAN be a bugger if you get your editor (textpad) to macro in queries though - as they'll naturally be set up to use $result, and if you don't amend them (hah, as if *I* would make such a silly mistake) it breaks.

David
 
Since php has an extension for everything else, I propose a 'variable_name_generate()' and 'variable_name_interpret()'. The free software hackers can handle the bulk of the code. Then Microsoft can extend an olive branch to the community by writing the 'do the thinking for me' stuff ;-)

----
JBR
 
They do have a variable_name_generate() ... It's called dropping the reference book on the keyboard, and see what keys it presses. ;)
 
So I'm not crazy or losing my mind. Other people actually use something other than just $result!

I kind of like the $userswithtenpostsnotonfivedayseatgrapes (just kidding!)

Maybe you could shorten it to $uwtpnofdeg
(or not)

tgus

____________________________
Families can be together forever...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top