12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- require_once("../../php/db_utils.php");
- try {
- // Connect to the database
- $database = db_connect();
-
- // Incoming data
- $canvasId = $_POST["canvas_id"];
- $ideaId = $_POST["idea_id"];
-
- // Declare query
- $query = 'SELECT comments.id, comments.comment, comments.collaborator, user.name, comments.date
- FROM comments
- INNER JOIN user ON comments.collaborator = user.username
- WHERE comments.canvas_id = "' . $canvasId . '"
- AND comments.idea_id = "' . $ideaId . '"
- ORDER BY comments.date;';
-
- // Run query
- $recordSet = db_query_return($database, $query);
-
- // Get comments by active user
- $comments = Array();
-
- // Declare index
- $index = 0;
-
- // For every comment
- while($record = $recordSet->fetch_assoc()) {
- $comments[$index]["id"] = $record["id"];
- $comments[$index]["comment"] = $record["comment"];
- $comments[$index]["collaborator"] = $record["collaborator"];
- $comments[$index]["name"] = $record["name"];
- $comments[$index]["date"] = $record["date"];
-
- // Increment index
- $index++;
- }
-
- mysqli_free_result($recordSet);
-
- echo(json_encode($comments));
-
- // Close the connection to the database
- db_close($database);
- }
- catch(Exception $e) {
- $errorMsg = $e->getMessage();
- print_r($errorMsg);
- }
- ?>
|