change…. so I switched to just putting all my output into a variable, then outputting it in a pesudo-template at the end of the script.
I also read of a difference in using
“stuff $php_variable stuff”, which is slower than
“stuff ” . $php_variable . ” stuff”, so I changed that where
appropriate as well. Additionally, ‘stuff’ is also faster, but by a neglible amount.
Here’s the old code:
[code]
while ($myrow = mysql_fetch_array($result)) {
if (mysql_errno() != 0) {
echo “Error ” . mysql_errno() .”
“;
} else { // end if (mysql_errno() != 0)
?>
“;
} else { // end if (mysql_errno() != 0)
$out .= “
$out .= ”
“;
$out .= ”
“;
$out .= ”
“;
$out .= ”
“;
$out .= ”
“;
$out .= ”
“;
$out .= ”
“;
} // end else
} // end while ($myrow = mysql_fetch_array($result))
[/code]
This was for about 425 rows, I believe.
I had no idea it made THAT much of a difference… Guess I’ll be using that on everything now… If not switching over to SMARTY or some other true templating system.
But if speed is a big issue for you then you may very well be better off doing it your way. I’m certainly not going to tell you which way you should do it. I just wanted to add an alternate viewpoint. 🙂
– Doug
The other nice thing can do is allow for MORE separation of code and presentation… I didn’t post the whole script, obviously, but most of the presentation (headers, footers, nav tables, etc) is at the END, with the $out variable placed where it needs to be. This makes whoever’s doing JUST the presentation much happier, since most of it is right there (away from the php code).
Granted, the mixing for data loops is elsewhere – but that’s minimal, once the rest of the page structure is set. You could also, potentially, have a few different output variables set up (I do a couple others for navigation in-page and site-wide, one of which is also pulled from the DB) and further help the presentation/data separation.
If you’re interested, I’ll post more example code to demonstrate.
—
—
ThatGuy
http://www.ddrkc.com
– Doug
With a minimal bit of work on the coder’s end, the design will be pretty much intact… You’d replace the data cells in each table with an output variable, and move the row design to that variable in your code loops…. Not a big deal, really. True, the updating isn’t QUITE so convenient when the design changes… but it’s still pretty minimal, and the speed and code separation benefits outweigh that small pain…
It’s much harder when you’re buiding the page as you go, and trying to figure out which bit to tweak in the mess, IMO.
—
—
ThatGuy
http://www.ddrkc.com
Now is a great time to check it out: ZDE 4 is in beta and they have some great incentives for beta participants!!