Re: php+html mixup in displaying multidimensional array in html tables [message #176847 is a reply to message #176846] |
Sat, 28 January 2012 20:14 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 1/28/2012 2:28 PM, Denis McMahon wrote:
> On Sat, 28 Jan 2012 12:24:14 +0100, John wrote:
>
>> I am new to this problem and shall be very grateful for any hint on how
>> to a´void an unreadable code-salad, when trying to display a
>> bidimensional array (thus with two indexes) on a html table. I refer to
>> the continuous shifting between<?php and<html> every two lines.
>>
>> Is there a method which is 'quick an easy' to do the job ?
>
> You mean something like:
>
> echo "<table>\n";
> foreach ($arr as $line) {
> echo "<tr>\n";
> foreach ($line as $cell) {
> echo "<td>$cell</td>\n";
> }
> echo "</tr>\n";
> }
> echo "</table>\n";
>
> This is a very crude solution, makes several assumptions, and has no
> testing of or handling for unexpected conditions. Depending on the data
> you feed it, it may crash or generate invalid markup, but under some
> conditions it might instead generate a valid table.
>
> The wonders of usenet will probably screw the formatting too. I can't do
> much about that.
>
> Rgds
>
> Denis McMahon
What is crude about it? What assumptions (other than the data does not
need to be run though htmlentities() or htmlspecialchars(), which is
quite easy to do)?
And what would crash?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|