PHP Classes

File: php/fetch-comment.php

Recommend this page to a friend!
  Classes of Ann   Purp Project   php/fetch-comment.php   Download  
File: php/fetch-comment.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Purp Project
Application to manage photo albums
Author: By
Last change: Update of php/fetch-comment.php
Date: 1 year ago
Size: 3,131 bytes
 

Contents

Class file image Download
<?php

//fetch_comment.php
session_start();
require_once
'includes/connect-db.php';
// $user_ID = $_SESSION['user']['id'];
$query = "SELECT * FROM `comments` WHERE `parent-id` = '0' ORDER BY id DESC";
$result = mysqli_query($connect, $query) or die("?????? " . mysqli_error($connect));

$comments_count = 0;
$count = 0;
$output = '';
for(
$i = 0; $i < mysqli_num_rows($result);$i++){
   
$comment = mysqli_fetch_array($result, MYSQLI_ASSOC);
   
// $comments += $comment;
    // print_r($comment);
   
$comments_count++;
   
   
$user_id = $comment["user-id"];
   
//var_dump($user_id);
   
$query_name = "SELECT login FROM `user` WHERE `id` = '$user_id' ";
   
$res = mysqli_query($connect, $query_name) or die("?????? " . mysqli_error($connect));
   
$username = mysqli_fetch_array($res, MYSQLI_ASSOC);
   
//var_dump($username["login"]);
   
if($comment["pic-id"] == $_SESSION["pic"]["id"]){
       
$output .= '
        <div class="panel panel-default">
        <div class="panel-heading">By <b>'
.$username["login"].'</b> on <i>'.$comment["date"].'</i></div>
        <div class="panel-body">'
.$comment["text"].'</div>
        <div class="panel-footer" align="right"><button type="button" class="btn btn-default reply" id="'
.$comment["id"].'">????????</button></div>
        </div>'
;
       
$output .= get_reply_comment( $comment["id"]);
    }
}
echo
$output;
//print_r($_SESSION["pic"]["id"]);


// $response = [
// "status" => true
// ];

// echo json_encode($response);

function get_reply_comment( $parent_id, $marginleft = 0){
   
$user_ID = $_SESSION['user']['id'];
    require
'includes/connect-db.php';
   
$query = " SELECT * FROM comments WHERE `parent-id` = '".$parent_id."'";
   
   
$result = mysqli_query($connect, $query) or die("?????? " . mysqli_error($connect));
   
//$comment = mysqli_fetch_array($result, MYSQLI_ASSOC);
   
$count = mysqli_num_rows($result);
   
$output = '';

  
   
    if(
$count > 0)
    {
       
$marginleft = $marginleft + 30;
        for(
$i = 0; $i < mysqli_num_rows($result);$i++){
           
$comment = mysqli_fetch_array($result, MYSQLI_ASSOC);
           
$user_id = $comment["user-id"];
           
//var_dump($user_id);
           
$query_name = "SELECT login FROM `user` WHERE `id` = '$user_id' ";
           
$res = mysqli_query($connect, $query_name) or die("?????? " . mysqli_error($connect));
           
$username = mysqli_fetch_array($res, MYSQLI_ASSOC);
           
$output .= '
            <div class="panel panel-default" style="margin-left:'
.$marginleft.'px">
            <div class="panel-heading">By <b>'
.$username["login"].'</b> on <i>'.$comment["date"].'</i></div>
            <div class="panel-body">'
.$comment["text"].'</div>
            <div class="panel-footer" align="right"><button type="button" class="btn btn-default reply" id="'
.$comment["id"].'">????????</button></div>
            </div>
            '
;
           
$output .= get_reply_comment( $comment["id"], $marginleft);
        }
    }
    return
$output;
}