Login pages... (quickie)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

I don't mean to be rude so please don't take this as a harsh/rude comment, but more of an observation.

It's time to buy a book.

It's not that you are un-aware of how mysql_error() works, it's that you aren't aware of using functions and their return values.

Any decent 'Learn PHP in 24 nanoseconds' type of book would have had you writing 'working' queries within the first few chapters...

Again, I'm not trying to be rude, or mean. I just think we've (by we I mean everyone else who's posted here) done about as much as we can to help you. We are here to help with problems, not teach the fundamentals of strings and functions: echo "mysql_error($password)"; ...

Please don't hate me :oops:
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post by Mightywayne »

Nick's got a point. But uh dude. xD That's not harsh at all. I suppose I could get a book, but I don't like the way they teach things. Like, I hate functions. Very rarely would I decide to use one, I just like to see all that code there. A lot of people don't. And a lot of people like to CAP THEIR TAGS, while I prefer to just have lowercase tags.

But yeah you've definitely got a point there. I should really know some of these things. I'm going to look more into this on my own. Thanks to all of you.

In jest, I point out the parenthesis in the topic title.

(quickie)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Avoiding functions severely limits, or rather hampers, your code moving forward. I'd strongly suggest you reconsider that position.

If you truly like to see all the code, may I suggest Assembly?
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

feyd wrote:If you truly like to see all the code, may I suggest Assembly?
haha feyd got jokes!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Mightywayne wrote:Nick's got a point. But uh dude. xD That's not harsh at all. I suppose I could get a book, but I don't like the way they teach things. Like, I hate functions. Very rarely would I decide to use one, I just like to see all that code there. A lot of people don't.
Wow ... it's the "art of programming" idea taken to it's logical extreme!

I'm not sure which is more astounding -- the assertion that all books teach things the same way, or that you should or should not use things like functions because of how you "feel" about them
(#10850)
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post by Mightywayne »

I read the functions article like, you personally make the functions, to help you later on in coding. I know there are some built-in to PHP, and I'd use those. I don't know if I'd make my own functions.

I'm not planning to make this like, a corporate job or whatever. It's going to be a nice little (big) game website. I usually learn as I go.

Now if functions, perhaps, made the server's code move faster or something, thus easing pressure on the server, then I'd care for them more.

It's also possible that I have no idea what a function is. If things like "echo" are a function, completely disregard my post.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Mightywayne wrote:I read the functions article like, you personally make the functions, to help you later on in coding. I know there are some built-in to PHP, and I'd use those. I don't know if I'd make my own functions.

I'm not planning to make this like, a corporate job or whatever. It's going to be a nice little (big) game website. I usually learn as I go.

Now if functions, perhaps, made the server's code move faster or something, thus easing pressure on the server, then I'd care for them more.

It's also possible that I have no idea what a function is. If things like "echo" are a function, completely disregard my post.
Disreguarded.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Imagine a situation where you need to calculate the commission of a sale, you are paying your employees 15% commission. You want to display the commission dollar value everywhere. One solution would be to pepper your code with

Code: Select all

echo "Your Commission is: ".($saleValue*.15);
Now, you have that line (or similar) throughout your site, dozens of times and everything is working great. Six months down the road, you want to be a kind boss and increase your commission rate to 17.5% -- You now have to search through all your code to find the places where you calculate the commission and change the values (.15 would become .175)

You'll be doing this dozens of times, maybe even in a few different files in different folders...

If you were to write a function to calculate the commission:

Code: Select all

function calcCommisssion($sales) {
   $commission = .15; // 15%
   return $sales*$commission;
}
And use it like so:

Code: Select all

echo "Your Commission is: ".calcCommission($saleValue);
Then, 6 months down the line, you just make a single change in the calcCommission function, and the changes are reflected everywhere you use that function.

Trust us, you will not succeed in programming your game (which you yourself admitted will be BIG) without the use of functions, I'll lay my reputation (assuming I have one ;)) on the line...
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post by Mightywayne »

Thank you, Nick, for the clarity. Guess I will be, then.

Also. JCart:

http://w3schools.com/php/php_functions.asp

Which calls what nick mentioned above, a function.

But then I look through their function list and find echo.

http://www.w3schools.com/php/func_string_echo.asp

And echo is a function! So they're both functions, then?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Yes echo is a function.. and I was refering to
If things like "echo" are a function, completely disregard my post.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

I thought that echo was a language construct and print() was a function. echo does not have a return value.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Daedalus- wrote:I thought that echo was a language construct and print() was a function. echo does not have a return value.
Both are language constructs
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Daedalus- wrote:I thought that echo was a language construct and print() was a function. echo does not have a return value.
Okay you got me there, it is not "technically a function" according to the manual. But in all fairness, neither is print ;)
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post by Mightywayne »

Editted out in case some folks try to hax0r me. Seriously. o_O;;
Last edited by Mightywayne on Fri Apr 06, 2007 2:24 pm, edited 1 time in total.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

I don't think you are on to something.

OOP is the way to go, imo.
Post Reply