Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How best to print an array to table?

5 views
Skip to first unread message

richard

unread,
May 24, 2012, 6:28:27 PM5/24/12
to
Ok so here's the quick and dirt simple code:

<?php

$Alist=array (

"cover"=>"images/A/A001.jpg",
"aname"=>"The A Team",
"bname"=>"An Empty Glass",
"artist"=>"SSgt Barry Sadler",
"avideo"=>"A",
"bvideo"=>"b",
"label1"=>"[US] RCA Victor",
"label2"=>"UK] RCA",
"adate"=>"4-23-66"
);

print "<table border='1'>";
print "<tr>";
print "<td>hello</td>";
print "</tr>";
print "</table>";

?>

I want to replace "hello" with $Alist "aname".
How is that done correctly in this instance?

Michael Fesser

unread,
May 24, 2012, 6:51:24 PM5/24/12
to

richard

unread,
May 24, 2012, 9:44:19 PM5/24/12
to
thanks

richard

unread,
May 24, 2012, 10:19:21 PM5/24/12
to
On Fri, 25 May 2012 00:51:24 +0200, Michael Fesser wrote:

Does not work in this case.
www.1littleworld.net/sample/test2.php

richard

unread,
May 24, 2012, 11:27:55 PM5/24/12
to
I think I've found the way to do this.

http://1littleworld.net/sample/test2a.php

Doug Miller

unread,
May 25, 2012, 10:09:23 AM5/25/12
to
richard <mem...@newsguy.com> wrote in news:1rna3htrhoisg.1ptae0yem1wvk$.dlg@
40tude.net:

[...]
>>
>> I want to replace "hello" with $Alist "aname".
>> How is that done correctly in this instance?
>
> I think I've found the way to do this.
>
> http://1littleworld.net/sample/test2a.php

You *do* realize that none of us can see your php code, don't you?

Denis McMahon

unread,
May 25, 2012, 12:24:12 PM5/25/12
to
On Thu, 24 May 2012 22:19:21 -0400, richard wrote:

> On Fri, 25 May 2012 00:51:24 +0200, Michael Fesser wrote:

>> print "<td>{$Alist['aname']}</td>";

> Does not work in this case.
> www.1littleworld.net/sample/test2.php

Perhaps you could show us the php you used, rather than link us to a
website that only shows us the results of that php.

The code suggested will work if you type it correctly. If you don't type
it correctly, eg miss out or change bits, it won't work.

Note for example, that:

The normal use may be $array["key"] or $array['key']

To be used inside a string delimited with "" needs the use of of '' for
the array key:

$array['key']

the whole $array['key'] has to be enclosed in the curly brackets:

{$array['key']}

Then it can be included in a string that is enclosed in double quotes:

print "{$array['key']}";

which can also include other text:

print "<td>{$array['key']}</td>";

Which bit did you fuck up? No $ symbol? Didn't use the curly brackets?
Put the curly brackets in the wrong places? Used the same quotes for the
array key as the string? Got the array name or key name wrong?

Here's an example of it working:

http://www.sined.co.uk/tmp/array_print.php

Using this php (irrelevant bits snipped):

$array = array( "cold"=>"penguin" );

$content .= "<p>The value of \"{\$array['cold']}\" is: \"{$array['cold']}
\"</p>";

Rgds

Denis McMahon

Denis McMahon

unread,
May 25, 2012, 12:33:56 PM5/25/12
to
No he doesn't. He thinks that we see all his php, and not just the result
of that php.

This is because he once opened a php file locally in his browser instead
of using the url for his server, and thus saw the raw php.

He then decided that the server sends the php to the browser, and despite
being told many times that he is wrong about this, has never accepted it.

I note that he is claiming that Micha's code was wrong, which it wasn't,
so he obviously messed up the application of Micha's example, but he
won't admit that, he'll just assert that Micha's example was wrong (It's
not, I've used it here <http://www.sined.co.uk/tmp/micha.php>) by
substituting Micha's code into his own table and that he has invented his
own solution instead.

Rgds

Denis McMahon

Captain Paralytic

unread,
May 30, 2012, 7:49:36 AM5/30/12
to
On May 25, 3:09 pm, Doug Miller <doug_at_milmac_dot_...@example.com>
wrote:
Of course he doesn't. This is RtS after all. Soon he willtell you that
it is your fault that yo cannot see his code, because you did it wrong.
0 new messages