|
Posted by Ivαn Sαnchez Ortega on 02/27/06 02:32
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Nancy wrote:
> First, I apologize if my posting format is improper.
That chunk of code makes my head spin. But apart from that, it's fine.
> Any efficiency pointers and stupid mistake notices are also welcome.
I cannot go through all that code, but I'll drop some suggestions:
- - Use variable expansion in your strings. It makes the code more legible.
e.g.:
<?php
db_query("select * from table where data_store_no = $store_no");
?>
- - Your db_query function may use global variables to store the DB
connection, and the query result. If this is the case, avoid nesting
db_query calls under any cost!! You might as well store all data from the
first query in an array, then loop through that array with foreach(), and
make sub-queries inside that loop.
e.g., the following doesn't work:
<?php
$r = mysql_query("select * from user where company_id = $company_id");
while($row = mysql_fetch_row($r))
{
$user_id =$row['id'];
// The following will overwrite the value of $r and mess with the previous
while loop:
$r = mysql_query("select * from orders where user_id = $user_id");
// (Do whatever with the data from the last query)
}
?>
Your code may be doing something like that behind the scenes.
- - Simplify and *understand* your code. If you don't know what does this
piece of code do, or why this bit is here, you're on the wrong track.
Declare functions and user docbook-style comments to know what the
different chunks of code do. The code you posted looks a bit like
gibberish.
- - KISS. Keep simple things simple. Do you have any real reasons to use
flattenArray or variable variables ($$data_count_values['data_select']) ??
- --
- ----------------------------------
IvΓ‘n SΓ‘nchez Ortega -i-punto-sanchez--arroba-mirame-punto-net
"Mostly harmless."
-- The Hitchhiker's Guide to the Galaxy.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQFEAkiv3jcQ2mg3Pc8RAv+bAJ9SmXFKapHNG/2mDLLS1MwjNu8K4ACghkVy
maI90arkXyInTPpaHZFpcPs=
=VZ/z
-----END PGP SIGNATURE-----
Navigation:
[Reply to this message]
|