· 9 years ago · Oct 11, 2016, 09:44 AM
1id money
2
31 23
4
52 345
6
73 111
8
9<table class="table table-striped">
10 <tr>
11 <th>Money</th>
12 </tr>
13 <tr ng-repeat="wcdrate in wcdrates">
14 <td>{{ wcdrate.money }}</td>
15 </tr>
16 </table>
17
18$http.post('./php/showMoney.php')
19 .success(function(data) {
20 $scope.wcdrates = data;
21 })
22 .error(function(err) {
23 $log.error(err);
24 })
25
26<?php
27define("__HOST__", "127.0.0.1");
28define("__USER__", "root");
29define("__PASS__", "");
30define("__BASE__", "davbaza");
31
32class DB {
33 private $con = false;
34 private $data = array();
35
36 public function __construct() {
37 $this->con = new mysqli(__HOST__, __USER__, __PASS__, __BASE__);
38
39 if(mysqli_connect_error()) {
40 die("DB connection failed:" . mysqli_connect_error());
41 }
42 }
43
44 public function qryPop() {
45 $sql = "SELECT * FROM `wcdrates` ORDER BY `id` DESC";
46 $qry = $this->con->query($sql);
47 if($qry->num_rows > 0) {
48 while($row = $qry->fetch_object()) {
49 $this->data[] = $row;
50 }
51 } else {
52 $this->data[] = null;
53 }
54 $this->con->close();
55 }
56
57
58
59 public function qryFire($sql=null) {
60 if($sql == null) {
61 $this->qryPop();
62 } else {
63 $this->con->query($sql);
64 $this->qryPop();
65 }
66 //$this->con->close();
67 return $this->data;
68 }
69}
70
71<?php
72
73include('connectDatabase.php');
74
75$db = new DB();
76
77$sql = "SELECT SUM(money) FROM wcdrates";
78
79$data = $db->qryFire();
80
81echo json_encode($data);
82
83CREATE TABLE IF NOT EXISTS `wcd_rate` (
84 `id` int(11) NOT NULL AUTO_INCREMENT,
85 `money` int(11) NOT NULL,
86 PRIMARY KEY (`id`)
87)