Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #4679

Re: php+html mixup in displaying multidimensional array in html tables

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: php+html mixup in displaying multidimensional array in html tables
Date 2012-01-29 15:09 -0500
Organization A noiseless patient Spider
Message-ID <jg4929$ov7$1@dont-email.me> (permalink)
References <jg0lpp$29b$1@nnrp.linuxfan.it> <4f244c53$0$5013$a8266bb1@newsreader.readnews.com> <jg1l00$rab$1@dont-email.me> <4f25a4eb$0$4921$a8266bb1@newsreader.readnews.com>

Show all headers | View raw


On 1/29/2012 2:58 PM, Denis McMahon wrote:
> On Sat, 28 Jan 2012 15:14:51 -0500, Jerry Stuckle wrote:
>
>> 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.
>
>> 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)?
>
> 1) If the sub arrays don't all contain the same number of elements, you
> could get a table with different numbers of cells in different rows.
> Ideally you ought to catch that somehow. One of the principles I was
> taught was about being liberal in what you accept as input and specific
> in what you generate as output.
>

This is from a MySQL query - multiple rows, all with the same number of 
columns.

> 2) What if an array member is a binary object or a class?
>

See above.

> Ultimately my solution is probably only suited to 2d arrays containing
> the same number of elements in each sub-array, and where each element in
> a sub-array is either an html safe string or a numeric value.
>

See above.

>> And what would crash?
>
> I have no idea what it will do if you feed it a binary object or a class
> as a sub-array element, but I suspect it may crash. Whatever it does do,
> from the point of view that the desired behaviour is that of "generating
> meaningful html", I doubt it would work as desired if eg
>

See above.

> $arr[3][2] = imagecreatetruecolor(640,480);
> $arr[1][3] = fopen("/path/file.type","r");
>
> etc etc
>
> Rgds
>
> Denis McMahon

Read the entire post.  None of your arguments are valid.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

php+html mixup in displaying multidimensional array in html tables John <John@agdp.de> - 2012-01-28 12:24 +0100
  Re: php+html mixup in displaying multidimensional array in html tables Luuk <Luuk@invalid.lan> - 2012-01-28 13:03 +0100
  Re: php+html mixup in displaying multidimensional array in html tables crankypuss <no@email.thanks> - 2012-01-28 05:07 -0700
  Re: php+html mixup in displaying multidimensional array in html tables Denis McMahon <denismfmcmahon@gmail.com> - 2012-01-28 19:28 +0000
    Re: php+html mixup in displaying multidimensional array in html tables Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-28 15:14 -0500
      Re: php+html mixup in displaying multidimensional array in html tables Denis McMahon <denismfmcmahon@gmail.com> - 2012-01-29 19:58 +0000
        Re: php+html mixup in displaying multidimensional array in html tables Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-29 15:09 -0500
          Re: php+html mixup in displaying multidimensional array in html tables Denis McMahon <denismfmcmahon@gmail.com> - 2012-01-29 22:10 +0000
            Re: php+html mixup in displaying multidimensional array in html tables Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-29 17:41 -0500
    Re: php+html mixup in displaying multidimensional array in html tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-28 22:01 +0100
      Re: php+html mixup in displaying multidimensional array in html tables Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-28 17:37 -0500
      Re: php+html mixup in displaying multidimensional array in html tables Michael Fesser <netizen@gmx.de> - 2012-01-29 00:02 +0100
        Re: php+html mixup in displaying multidimensional array in html tables The Natural Philosopher <tnp@invalid.invalid> - 2012-01-28 23:08 +0000
  Re: php+html mixup in displaying multidimensional array in html tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-28 21:43 +0100
  Re: php+html mixup in displaying multidimensional array in html tables "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-29 00:50 +0100
    Re: php+html mixup in displaying multidimensional array in html tables r.mariotti@fdcx.net - 2012-01-29 06:55 -0500
      Re: php+html mixup in displaying multidimensional array in html tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-29 15:43 +0100
        Re: php+html mixup in displaying multidimensional array in html tables Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-29 10:44 -0500
          Re: php+html mixup in displaying multidimensional array in html tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-29 17:15 +0100
            Re: php+html mixup in displaying multidimensional array in html tables Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-29 11:45 -0500
              Re: php+html mixup in displaying multidimensional array in html tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-29 18:41 +0100
                Re: php+html mixup in displaying multidimensional array in html tables Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-29 13:49 -0500
                Re: php+html mixup in displaying multidimensional array in html tables Scott Johnson <noonehome@chalupasworld.com> - 2012-01-30 06:04 -0800
                Re: php+html mixup in displaying multidimensional array in html tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-30 16:03 +0100
        Re: php+html mixup in displaying multidimensional array in html tables Scott Johnson <noonehome@chalupasworld.com> - 2012-01-30 05:51 -0800
          Re: php+html mixup in displaying multidimensional array in html tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-30 16:27 +0100

csiph-web