At 04:41 PM 9/18/02 -0400, Support @ Fourthrealm.com wrote:
>Which is more efficient?

Considering that the difference in efficiency is so small, a more important
question is which is clearer to the programmer?

I prefer b, except that I allow short tags and use the magic print/echo 
function:

<?=$Title?>  thusly...


$result = mysql_query( ... );

?>
<TABLE>
<TR>
    <TH>Title</TH>
</TR>

<? while( extract( mysql_fetch_array( $result,  MSQL_ASSOC )))  : ?>
<TR>
    <TD>
       <?=$title?>
    </TD>
</TR>

<? endwhile ?>
</TABLE>



PHP by itself is a fantastic template language!

If you aren't doing anything else in a script, mysql_free_result is not needed
in a script like this because the result set will be cleaned up by PHP when
the script ends.

Rick



>a) a sql loop where everything is displayed/formatted using echo stmts, 
>like this:
>
>$result = mysql_query("SELECT * FROM news WHERE active=1");
>while ($row = mysql_fetch_object($result)) {
>         echo "<TR><TD>$row->title </TD></TR>";
>}
>mysql_free_result($result);
>
>?>
>
>
>OR
>b) a sql loop where you break in and out of php tags as needed:
>
><?php
>$result = mysql_query("SELECT * FROM news WHERE active=1");
>while ($row = mysql_fetch_object($result)) {
>?>
><TR><TD>
>         <?php echo "$row->title"; ?>
></TD></TR>
>
><?php
>}
>mysql_free_result($result);
>
>?>
>
>
>Obviously, these are really simplified examples.  Typically the html code 
>gets much more complicated.
>
>
>Peter
>
>
>- - - - - - - - - - - - - - - - - - - - -
>Fourth Realm Solutions
>[EMAIL PROTECTED]
>http://www.fourthrealm.com
>Tel: 519-739-1652
>- - - - - - - - - - - - - - - - - - - - -
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to