<?php
// Include DB file for credentials and database connection 
include("db.php");

error_reporting(E_ALL);

/* Validate Request */
include("auth_api.php");

if ($_SERVER['REQUEST_METHOD'] === 'PUT') {

$data = json_decode(file_get_contents('php://input'), true);			

// $stmt=$conn->prepare("SELECT * FROM `tbl_videos_ve` v inner join `tbl_videos_ve_domain` d on d.id=v.domain inner join `tbl_videos_ve_cat` c on c.id=v.cat_id where d.name=?");

//catName clientName country creationDate domainName rating tags

// $stmt=$conn->prepare("SELECT * FROM `tbl_videos_ve` v inner join `tbl_videos_ve_domain` d on d.id=v.domain inner join `tbl_videos_ve_cat` c on c.id=v.cat_id where d.name=? or c.name=? or e.name=? or f.name=? or g.name=? or h.name=? or i.name=? or j.name=?");

// $stmt->bind_param('sssssss',$data['domainName'],$data['catName'],$data['clientName'],$data['country'],$data['creationDate'],$data['rating'],$data['tags']);


		// $stmt->bind_param('s',$data['domainName']);
		// $stmt->execute();
		// $find=$stmt->get_result();

		$sql  = 'SELECT * FROM `tbl_videos_ve`';
		$find = $conn->query($sql);

		if($find->num_rows > 0) { 

			while( $row = $find->fetch_assoc() ) {			

				//echo '<pre>';
				//print_r($row);

				$items[] = ["<tr><td>" .$row['id']. "</td><td>" . $row['title']. "</td><td>" . "https://www.youtube.com/watch?v=".$row['youtube_video_id']. "</td><td>" . $row['cat_id']. "</td><td>" . $row['quote']. "</td><td>" . $row['quote_long']. "</td><td>" . $row['client_name']. "</td><td>" . $row['company_name']. "</td><td>" . $row['designation']. "</td><td>" . $row['city']. "</td><td>" . $row['state']. "</td><td>" . $row['country']. "</td><td>" . $row['domain']. "</td><td>" . $row['status']. "</td><td>" . $row['website']. "</td><td>" . $row['remarks']. "</td><td>" . $row['average_rating']. "</td><td>" . $row['uploaded_by']. "</td><td>" . $row['creation_date']. "</td><td>" . $row['uploaded_at'] . "</td></tr>"];
				//$items[] = $row['id'];

            }			
			$return = array('success' => true, 'message' => 'Data Exported Successfully!', 'data' => $items);		

		} else { 

			$return = array('success' => false, 'message' => 'No record found!', 'data' => NULL);

		}

		echo json_encode($return);

}

