du kunne nemt selv have decode json listen
$str = '{"emails":[{"group":"Idag","list":[{"id":1,"subject":"test","to":["test"],"body":"test","time":"test","datetime":"test","from":"test2","dp":"asds","dpRetina":"ads"}]}]}';
print_r( json_decode($str));
her er lidt du kan arbejde ud fra
test data sql
--
-- Database: `test`
--
-- --------------------------------------------------------
--
-- Struktur-dump for tabellen `tbl_newsletter`
--
CREATE TABLE IF NOT EXISTS `tbl_newsletter` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`subject` varchar(255) COLLATE utf8_danish_ci NOT NULL,
`body` text COLLATE utf8_danish_ci NOT NULL,
`time` varchar(255) COLLATE utf8_danish_ci NOT NULL COMMENT 'bør have datatypen time',
`datetime` varchar(255) COLLATE utf8_danish_ci NOT NULL COMMENT 'bør have datatypen datetime',
`n_from` varchar(255) COLLATE utf8_danish_ci NOT NULL COMMENT 'from er et reseveret ord i sql',
`dp` varchar(255) COLLATE utf8_danish_ci NOT NULL,
`dpRetina` varchar(255) COLLATE utf8_danish_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci AUTO_INCREMENT=2 ;
--
-- Data dump for tabellen `tbl_newsletter`
--
INSERT INTO `tbl_newsletter` (`id`, `subject`, `body`, `time`, `datetime`, `n_from`, `dp`, `dpRetina`) VALUES
(1, 'test', 'test', 'test', 'test', 'test2', 'asds', 'ads');
-- --------------------------------------------------------
--
-- Struktur-dump for tabellen `tbl_user`
--
CREATE TABLE IF NOT EXISTS `tbl_user` (
`id` int(10) NOT NULL,
`firstname` varchar(255) COLLATE utf8_danish_ci DEFAULT NULL,
`lastname` varchar(255) COLLATE utf8_danish_ci DEFAULT NULL,
`email` varchar(255) COLLATE utf8_danish_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci;
--
-- Data dump for tabellen `tbl_user`
--
INSERT INTO `tbl_user` (`id`, `firstname`, `lastname`, `email`) VALUES
(2, 'Ronny', 'Olsen', 'udvikleren@olsensweb.dk'),
(21, 'Rip', 'And', 'rip@andeby.dk'),
(22, 'Rap', 'And', 'rap@andeby.dk'),
(23, 'Rup', 'And', 'rup@andeby.dk');
test code
<?php
$to = array();
$mail_list = array();
$conn = new PDO("mysql:host=localhost;dbname=test;charset=utf8", "root", "");
$sql = "SELECT * FROM tbl_user";
$rs = $conn->query($sql) or die(var_export($conn->errorinfo(), TRUE));
while ($obj = $rs->fetch(PDO::FETCH_OBJ)) {
$to[] = $obj->firstname . " " . $obj->lastname . " <" . $obj->email . ">";
}
// print_r($to);
// $to= array("test");
$sql = "SELECT * FROM tbl_newsletter where id =1";
$rs = $conn->query($sql) or die(var_export($conn->errorinfo(), TRUE));
$obj = $rs->fetch(PDO::FETCH_OBJ);
// hvis jeg ikke typecaster id vil det komme ud som en string
$mail_list = array(
"id" => (int) $obj->id,
"subject" => $obj->subject,
"to" => $to,
"body" => $obj->body,
"time" => $obj->time,
"datetime" => $obj->datetime,
"from" => $obj->n_from,
"dp" => $obj->dp,
"dpRetina" => $obj->dpRetina
);
// var_dump($mail_list);
$ar = array(
"emails" => array(
array(
"group" => "Idag",
"list" => array($mail_list),
),
)
);
echo json_encode($ar);
?>