Reputation: 65
bit of a newbie here.
I have the below code which gets data from a data and formats it as a json string. But how can I put this into my js to work with the code there?
PHP / Json encode
<?php include "db.php" ?>
<?php
echo " <br /> Currently Viewing Feedback For 13 <br /> <br /> <br /> <br /> ";
$result = mysqli_query($db_connection, "SELECT * FROM feedback");
while ($row = $result->fetch_assoc()){
echo "<br /> <br /> <br />";
echo json_encode($result);
}
?>
Upvotes: 0
Views: 91
Reputation: 130
right here, you just try to encode the mysqli_result into json that's not the right thing to do.. And, don't try to put HTML into your JSON response ;)
<?php include "db.php"
echo " <br /> Currently Viewing Feedback For 13 <br /> <br /> <br /> <br /> ";
$result = mysqli_query($db_connection, "SELECT * FROM feedback");
$finalResult = array();
while ($row = $result->fetch_assoc()){
$finalResult[] = $row;
}
echo json_encode($finalResult);
?>
Upvotes: 1