Re: mixing HTML and PHP code
| From: | Alex Black | Date: | Fri, 12 Jan 2001 23:47:51 +0000 |
| Subject: | Re: mixing HTML and PHP code | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-34324@lists.php.net to get a copy of this message | ||
> <?
> connect_to_database();
> parse_query();
> execute_query();
>
> echo "<TABLE>";
>
> while (fetch_row_from_query())
> {
> $output = data_from_fetched_row();
> $more_output = more_data_from_fetched_row();
>
> echo "<TR><TD> $output </TD><TD> $more_output
> </TD></TR>";
>
> }
> echo "</TABLE>";
> ?>
Well, this may be a bit specific, but that is probably part of your problem.
You have no structure associated with your application design:
what are you doing making a connection to a database on the same page you
spit out the results from?
You should be including a wrapper file, and calling a function which talks
to the database.
Also, all of that logic should be in a file that is separate from the markup
_anyway_
> <?
> connect_to_database();
> parse_query();
> execute_query();
> ?>
> <TABLE>
> <? while (fetch_row_from_query()) : ?>
>
> <? $output = data_from_fetched_row();
> $more_output = more_data_from_fetched_row(); ?>
>
>
> <TR><TD><?=$output?></TD><TD><?=$more_output?></TD></TR>
>
> <? endwhile; ?>
> </TABLE>
<table>
<? function html_table_row($output, $more_output) { ?>
<tr>
<td valign="middle" bgcolor="#CCCCCC"><?=$output?></td>
<td valign="middle" bgcolor="#CCCCCC"><?=$more_output?></td>
</tr>
<? } ?>
</table>
>
>
> I _personally_ prefer the upper implementation, as all my web developing team
> (that is, only me :-) know both PHP and HTML and don't
> like the code to be *plagued* of <? ?> <? ?> <? ?> as in above example.
I digress.
_alex
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>