-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFolderGeneration.php
More file actions
52 lines (40 loc) · 1.2 KB
/
Copy pathFolderGeneration.php
File metadata and controls
52 lines (40 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
// session_start();
$repo_id=$_GET['repo_id'];
require "db.php";
//$con = mysqli_connect('localhost','bhavya','bhavya123','gitrepo');
$sql = "SELECT dir_id,name,parent_dir FROM dir WHERE repo_id = $repo_id";
$Stmt=$pdo->prepare($sql);
$Stmt->execute();
$json_array = array();
while($row=$Stmt->fetch(PDO::FETCH_ASSOC))
{
if($row['parent_dir'] == -1){
$row['parent_dir'] = '#';
}
$json_array[] = $row;
}
//echo (json_encode($json_array));
$sql1 = "SELECT f_id,name,parent_dir FROM files WHERE repo_id = $repo_id";
$Stmt=$pdo->prepare($sql1);
$Stmt->execute();
$json_array1 = array();
while($row1=$Stmt->fetch(PDO::FETCH_ASSOC))
{
if($row1['parent_dir'] == -1){
$row1['parent_dir'] = '#';
}
$json_array1[] = $row1;
}
json_encode($json_array1);
$result = array_merge($json_array,$json_array1);
//$test = ['f_id' => 2, 'name' => 'test', 'parent_dir' => 'test2', 'dir_id' => 2];
$rewriteKeys = array('f_id' => 'id', 'name' => 'text', 'parent_dir' => 'parent', 'dir_id' => 'id');
$newArr = array();
foreach ($result as $index => $item){
foreach ($item as $key => $value) {
$newArr[$index][$rewriteKeys[$key]] = $value;
}
}
echo(json_encode($newArr));
?>