Cyerus
Galactic Dominion Eternal Strife
|
Posted - 2011.04.02 00:10:00 -
[1]
Edited by: Cyerus on 02/04/2011 00:14:41 Hi,
First I should thank you for trying to create something like this. As you said, your PHP skills aren't that good, and can easily be seen by checking out your code. Here are some things you need to pay more attention to;
* Stop using die() There is no need whatsoever to use die(). Everything can be caught by some if...else statements.
Instead of;
if(statement) { die("Error"); } do_something();
Try;
if(!statement) { do_something(); } else { echo "error"; }
Or the bigger version;
if(!statement) { if(!other_statement) { do_something(); } else { echo "other error"; } } else { echo "error"; }
* Variable outside the quotes
Wrong;
format("Checking... $fetchCharacterName\n", "Checking... $fetchCharacterName<br />");
Good;
format("Checking... " . $fetchCharacterName . "\n", "Checking... $" . $fetchCharacterName . "<br />");
* PHP 'echo' is slow, and should be avoided for big texts
duplicates.php
echo "<html> .... ";
Instead, just close the PHP tag ( !> ), and let the HTML just be passed along. Variables always need to be outside the quotes, and can be echo'd by using using;
<!php echo $c->banner; !>
* Only 1 database connection is enough
Instead of every function calling the database on it's own (and hence repeating the same piece of code over and over), just make a seperate function and do the database connection there. All the tables are loaded in the same database, meaning that select_db() function can be set in that function aswell. For example;
function do_DB($host, $user, $pass, $db) { $connect = mysql_connect($host, $user, $pass); if($connect) { $link = mysql_select_db($db, $db); if($link) { return $link; } else { return false; } } else { return false; } }
$link = do_DB($c->db_host, $c->db_user, $c->db_pass, $c->db_name); if($link) { echo "Connection succesful";
do_stuff();
mysql_close($link); } else { echo "Connection failed; " . mysql_error($link); }
After you get this under control, you want to remove PHP from the template. Meaning that no PHP will be used inside the template, instead tags like {$variable} will pe parsed by a template engine. RainTPL is a very fast one, having all the functions you need. Also things like CSS and JavaScript should be made seperate files, for caching purposes.
I hope this helps.
~Cyerus
|