PDA

View Full Version : Does this go here? PHP stuff.....


darelf
03-17-2004, 10:02 AM
I'm not sure if this goes here... I'll move it otherwise...

I wanted to get some people to look at some php code I'm working on as I work on it, and suggest better ways/methods of doing different things in the code....

Plus suggestions on how to document php in-line... i.e. what is the most useful to the most people when looking at php. (php seems pretty straight-forward to me, so I don't put many comments in the code).

I'm using a mix of forms and sessions and mysql, and so a lot of little things I'm simply not aware of may seem very obvious to someone else.

Anyway, it's a vanity project for a group of friends, and it is for creating characters in a P&P RPG game called Imagine. That's not really important, though, it's the code I'm interested in making better with suggestions.

My php is all self-taught, so I'm sure there will be a lot of things I could be doing better/cleaner/smarter.

This is basically an invitation to take a look and make comments if you have them.

The source of the site can be accessed as plain text here - http://www.mythicrpg.com/php-source/project

And the regular view would be - http://www.mythicrpg.com/project/imagine.php

It's very rough, and the different parts are separated into a checklist format which I will collapse later on. Anyway, any and all comments are welcome. You can post responses, or email me at ( darelf at earthlink dot net ).

gsoft
03-18-2004, 06:41 AM
on file imagine-support.php


if ($race == "Midfolk") {
$base = 36;
} elseif ($race == "Dwarf") {
$base = 42;
} elseif ($race == "Avian" || $race == "Elf") {
$base = 60;
} elseif ($race == "Human" || $race == "Goblin") {
$base = 72;
} elseif ($race == "Centaur" || $race == "Saurian") {
$base = 78;
} else {
$base = 84;
}


Use a switch statement the if/elseif/else is suppose to look like so


if () {

} else if () {

} else {

}

If you have more than one else if you should require the switch. That goes for all the if/elseif/else statements you have in that file it should make it a lot faster.

Other than that its not bad

darelf
03-18-2004, 08:37 AM
On the switch...case thing:

How would I do the number series checks in a switch? Where I have something like:

if ($x < 5) { do y }
elseif ($x < 10) { do z }

etc.

This would do y for $x = 1 through 4 and do z for $x = 5 through 9, etc etc.

stuka
03-18-2004, 10:12 AM
A simple way is 'fall-through' processing: switch($x){
case 1:
case 2:
case 3:
case 4:
//do stuff
break;
case 5:
//and so on
} One useful property of this structure is that you can add intervening cases later if need be.

darelf
03-18-2004, 11:01 AM
Originally posted by Stuka
A simple way is 'fall-through' processing:

Well... yes, but what if the range of numbers is large... say 20 or 30 values? Is there a way to specify a range?

stuka
03-18-2004, 12:05 PM
I don't think so. In that case I think you probably need to reconsider your overall structure to remove the if...else stuff. One likely useful idea is to create classes, and have processing handled inside the class, rather than in the main code.