Page 4 of 5

Posted: Thu Jan 18, 2007 10:21 pm
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:

Posted: Fri Jan 19, 2007 10:58 am
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)

Posted: Fri Jan 19, 2007 9:00 pm
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?

Posted: Fri Jan 19, 2007 10:18 pm
by daedalus__
feyd wrote:If you truly like to see all the code, may I suggest Assembly?
haha feyd got jokes!

Posted: Sat Jan 20, 2007 12:10 am
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

Posted: Sat Jan 20, 2007 2:18 pm
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.

Posted: Sat Jan 20, 2007 2:33 pm
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.

Posted: Sat Jan 20, 2007 2:43 pm
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...

Posted: Sat Jan 20, 2007 3:40 pm
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?

Posted: Sat Jan 20, 2007 3:42 pm
by John Cartwright
Yes echo is a function.. and I was refering to
If things like "echo" are a function, completely disregard my post.

Posted: Sat Jan 20, 2007 3:52 pm
by daedalus__
I thought that echo was a language construct and print() was a function. echo does not have a return value.

Posted: Sat Jan 20, 2007 3:55 pm
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

Posted: Sat Jan 20, 2007 3:55 pm
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 ;)

Posted: Sat Jan 20, 2007 4:49 pm
by Mightywayne
Editted out in case some folks try to hax0r me. Seriously. o_O;;

Posted: Sat Jan 20, 2007 8:12 pm
by daedalus__
I don't think you are on to something.

OOP is the way to go, imo.