Reply to Re: Complicated while loop for a simpleton

Your name:

Reply:


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-----

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация