0

I have been trying to figure out how to populate a html template with data from a multi dimensional array, but i cant figure it out. The template is taken from MySQL.

This is what I have:

$template=addslashes($row['content']);

eval("\$body=\"$template\";");

print($body);

Now the template is as follows:

$row['content'] = "<html><p>array item one $arr[0][0]</p><p>array item two $arr[0][1]</p></html>"

...and the array ($arr):

Array ( [0] => Array ( [0] => 1 [1] => 6 ) )

The result is:

$body = <html><p>array item one Array[0]</p><p>array item two Array[1]</p></html>

...as opposed to what I expected:

$body = <html><p>array item one 1</p><p>array item two 6</p></html>

I can get this to work fine with 'solo variables' but it just wont return 'array variables'...

Anyone have any ideas where I am going wrong? I appologise in advance for my limited knowledge, im still learning. :)

Edited by NuGG: typo

2
Contributors
2
Replies
9
Views
2 Years
Discussion Span
Last Post by NuGG
0

You need to change the template anyhow:

//$arr set previously;

//$template = "<html><p>array item one {$arr[0][0]}</p><p>array item two {$arr[0][1]}</p></html>";

echo $template;
0

Aha! You are right. Thanks for your help, I knew it would be something simple.

Solved.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.