FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » How best to print an array to table?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
How best to print an array to table? [message #178251] Thu, 24 May 2012 22:28 Go to next message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
Senior Member
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?
Re: How best to print an array to table? [message #178252 is a reply to message #178251] Thu, 24 May 2012 22:51 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(richard)

> 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?

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

Curly syntax
http://www.php.net/manual/en/language.types.string.php#language.types.strin g.parsing.complex

Micha

--
http://mfesser.de/blickwinkel
Re: How best to print an array to table? [message #178253 is a reply to message #178252] Fri, 25 May 2012 01:44 Go to previous messageGo to next message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
Senior Member
On Fri, 25 May 2012 00:51:24 +0200, Michael Fesser wrote:

> .oO(richard)
>
>> 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?
>
> print "<td>{$Alist['aname']}</td>";
>
> Curly syntax
> http://www.php.net/manual/en/language.types.string.php#language.types.strin g.parsing.complex
>
> Micha

thanks
Re: How best to print an array to table? [message #178254 is a reply to message #178252] Fri, 25 May 2012 02:19 Go to previous messageGo to next message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
Senior Member
On Fri, 25 May 2012 00:51:24 +0200, Michael Fesser wrote:

> .oO(richard)
>
>> 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?
>
> print "<td>{$Alist['aname']}</td>";
>
> Curly syntax
> http://www.php.net/manual/en/language.types.string.php#language.types.strin g.parsing.complex
>
> Micha

Does not work in this case.
www.1littleworld.net/sample/test2.php
Re: How best to print an array to table? [message #178255 is a reply to message #178251] Fri, 25 May 2012 03:27 Go to previous messageGo to next message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
Senior Member
On Thu, 24 May 2012 18:28:27 -0400, richard wrote:

> 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?

I think I've found the way to do this.

http://1littleworld.net/sample/test2a.php
Re: How best to print an array to table? [message #178264 is a reply to message #178255] Fri, 25 May 2012 14:09 Go to previous messageGo to next message
Doug Miller is currently offline  Doug Miller
Messages: 171
Registered: August 2011
Karma: 0
Senior Member
richard <member(at)newsguy(dot)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?
Re: How best to print an array to table? [message #178265 is a reply to message #178254] Fri, 25 May 2012 16:24 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
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
Re: How best to print an array to table? [message #178266 is a reply to message #178264] Fri, 25 May 2012 16:33 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Fri, 25 May 2012 14:09:23 +0000, Doug Miller wrote:

> richard <member(at)newsguy(dot)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?

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
Re: How best to print an array to table? [message #178301 is a reply to message #178264] Wed, 30 May 2012 11:49 Go to previous message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On May 25, 3:09 pm, Doug Miller <doug_at_milmac_dot_...@example.com>
wrote:
> 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?

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.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Problem setting Date field in MySQL
Next Topic: What is this attack trying to do?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 07:47:49 GMT 2024

Total time taken to generate the page: 0.02356 seconds