I am rewrting a newsletter-thingy.
I have a table for all newsletter fields, that is like this:
field_uid | field_name | field_content | field_letter_id
Where f.x. the column field_name
can have the value letter_headline
and the column field_content
can have the value My headline
.
When I do this:
$fields = $this->db->dbh->query("SELECT field_name, field_content FROM newsletter_fields WHERE field_letter_uid = '". $letter_id ."'");
foreach($fields->fetchAll(PDO::FETCH_ASSOC) as $key) {
print_r($key);
}
It will correctly give me this:
Array ( [field_name] => letter_image0 [field_content] => image.jpg )
Array ( [field_name] => letter_headline [field_content] => My headline )
Array ( [field_name] => letter_headline_size [field_content] => 12 )
Array ( [field_name] => letter_sub_headline [field_content] => My subheadline )
Array ( [field_name] => letter_sub_headline_size [field_content] => 10 )
Array ( [field_name] => letter_content [field_content] => Letter content )
Array ( [field_name] => letter_link [field_content] => www.example.com )
Array ( [field_name] => letter_link_txt [field_content] => Example )
What I want is to build an array like this
$field["letter_image"] = "image.jpg";
$field["letter_headline"] = "My headline"
And then I can output the content with:
echo $field["letter_image"];
But I can't seem to figure out how to set the field array.