I send data via json. It is working well:
$.ajax({
url: "json.php",
type: "POST",
dataType: "json",
encode: true,
data: {},
success: function (data) {
$(".blue").html(data.blue);
$(".red").html(data.red);
}
});
json.php
$array['blue'] = "blue array";
$array['red'] = "red content";
echo json_encode($array);
My problem is now, that instead of..
blue array
...I want to send:
$pdo = $db->query('SELECT * FROM data;');
while ($row = $pdo->fetch(PDO::FETCH_ASSOC)) {
echo "<li>".$row['name']."</li>";
}
is this possible?
Here's an extremely basic example:
<?php
$json = array(
'blue' => '',
'red' => 'Empty red content or whatever'
);
$pdo = $db->query('SELECT * FROM data;');
while ($row = $pdo->fetch(PDO::FETCH_ASSOC)) {
$json['blue'].= "<li>".$row['name']."</li>";
}
echo json_encode($json);
Not sure what logic you would use to actually populate red
but you can work it into the while loop or whatever.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments