-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.php
More file actions
72 lines (46 loc) · 1.69 KB
/
Copy pathapi.php
File metadata and controls
72 lines (46 loc) · 1.69 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
$server = "localhost";
$username = "root";
$password = "";
$dbname = "datathon";
mb_internal_encoding('UTF-8');
$connection = new mysqli('127.0.0.1', $username, $password, $dbname);
$connection->set_charset("utf8");
header("content-type: text/html; charset=UTF-8");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$tableName = 'products';
//$result = $connection->query("SELECT name FROM $tableName");
//$array = $result->fetch_assoc();
$result = $connection->query("SELECT fk_product_name,(SELECT name from categories where id = fk_category_id) FROM products_stores");
$a = $result->fetch_all();
function christos($connection,$query) {
$ar = array();
//$result = $connection->query("SELECT name FROM $tableName");
//$array = $result->fetch_assoc();
$result = $connection->query($query);
while($row = $result->fetch_assoc()) {
// echo "<pre>";
// print_r($row);
// echo "</pre>";
array_push($ar,$row);
}
return $ar;
}
$tempo = christos($connection,"SELECT fk_product_name,(SELECT name from categories where id = fk_category_id) FROM products_stores");
//print_r($tempo) ;
$result = array();
foreach ($tempo as $key => $value){
//echo $value['fk_product_name'];
//$bam = $value['(SELECT name from categories where id = fk_category_id)'] . ' ' . $value['fk_product_name'];
// echo $bam;
$raous = $value['(SELECT name from categories where id = fk_category_id)'] . ' | ' . $value["fk_product_name"];
array_push($result,$raous);
}
//echo $result[100];
echo json_encode($result);
?>