-
Notifications
You must be signed in to change notification settings - Fork 0
/
product_model.php
186 lines (134 loc) · 6.19 KB
/
product_model.php
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Product_model extends CI_Model {
public function getProducts()
{
return $this->db->query("SELECT t1.*,t2.category as icategory, t3.region as iregion FROM industry t1
LEFT JOIN category_industry t2 ON t1.category=t2.id
LEFT JOIN region t3 ON t1.region = t3.id ORDER BY t1.name ASC")->result_array();
}
public function getTools($cat)
{
return $this->db->query("SELECT t1.*,t2.category as icategory, t3.region as iregion FROM industry t1
LEFT JOIN category_industry t2 ON t1.category=t2.id
LEFT JOIN region t3 ON t1.region = t3.id WHERE t2.category='$cat' ")->result_array();
}
public function getTool($id)
{
return $this->db->query("SELECT t1.*,t2.category as icategory, t3.region as iregion FROM industry t1
LEFT JOIN category_industry t2 ON t1.category=t2.id
LEFT JOIN region t3 ON t1.region = t3.id WHERE t1.id='$id' ")->result_array();
}
public function getTable($table)
{
return $this->db->get($table)->result_array();
}
public function countAll($table)
{
return $this->db->count_all($table);
}
public function search()
{
$keyword = mysql_real_escape_string(trim($this->input->post('searchInput')));
$category = $this->input->post('category');
if($category == ''){
$category = "%%";
}
$region = $this->input->post('region');
if($region == ''){
$region = "%%";
}
$capacity= $this->input->post('capacity');
if($capacity == ''){
$capacity = "%%";
}
$search5= $this->input->post('search5');
$search4= $this->input->post('search4');
$list= $this->input->post('list');
$keyword1 = mysql_real_escape_string(trim($this->input->post('searchInput1')));
if($search4 == '' && $search5 == '' ){
$search4 = "";
$search5 = "";
}else {
return $this->db->query("SELECT t1.*,t2.category as icategory, t3.region as iregion FROM industry t1
LEFT JOIN category_industry t2 ON t1.category=t2.id
LEFT JOIN region t3 ON t1.region = t3.id
WHERE capacity BETWEEN $search4 AND $search5 AND capacity like '%$list%'
ORDER BY t1.name ASC")->result_array();
}
return $this->db->query("SELECT t1.*,t2.category as icategory, t3.region as iregion FROM industry t1
LEFT JOIN category_industry t2 ON t1.category=t2.id
LEFT JOIN region t3 ON t1.region = t3.id
WHERE t1.name like '%$keyword%' and t1.category like '$category' and t1.region like '$region' and type_product like '%$keyword1%'
ORDER BY t1.name ASC")->result_array();
}
public function get_industry($id) {
return $this->db->query("SELECT * FROM industry WHERE id=$id")->result_array();
}
public function getPage($page)
{
return $this->db->query("SELECT * FROM category_industry WHERE category='$page' LIMIT 1")->row_array();
}
public function getCategories()
{
return $this->db->query("SELECT id, category FROM category_industry ORDER BY id")->result_array();
}
public function getSubcategory($page)
{
return $this->db->query("SELECT t1.id,t1.category,t2.id,t2.name FROM category_industry t1
JOIN industry t2 ON t1.id=t2.category WHERE t1.category='$page'")->result_array();
}
public function getSubcategoryPage($id)
{
if($id != NULL)
return $this->db->query("SELECT t1.*,t2.id,t2.category FROM industry t1, category_industry t2 WHERE t1.id=$id and t2.id=t1.category LIMIT 1")->row_array();
else
return FALSE;
}
public function getNews($category)
{
return $this->db->query("SELECT id,title,news_date,image,count_view FROM news WHERE category = $category ORDER BY id DESC LIMIT 5")->result_array();
}
public function getOneNews($id)
{
$this->db->query("UPDATE news SET count_view = count_view + 1 WHERE id=$id");
$result = $this->db->query("SELECT * FROM news WHERE id=$id LIMIT 1")->row_array();
return $result;
}
public function getLatestNews($limit,$start)
{
return $this->db->query("SELECT t1.id, t1.title, t1.image, t1.news_date,t1.count_view, t2.title as category FROM news t1, category_news t2 WHERE t1.category=t2.id ORDER BY id DESC LIMIT $start, $limit")->result_array();
}
public function countRecords($table)
{
return $this->db->count_all($table);
}
function register_user($name,$surname,$lastname,$user_name,$user_password,$user_email) {
$this->db->query("INSERT INTO users (name,surname,lastname,user_name,user_password,user_email) VALUES ('$name','$surname','$lastname','$user_name','$user_password','$user_email')");
}
function comment($name,$email,$msg) {
$this->db->query("INSERT INTO msgs (name,email,msg) VALUES ('$name','$email','$msg')");
}
function viewcomment() {
return $this->db->query("SELECT id,name,email,msg,UNIX_TIMESTAMP(datetime) as dt FROM msgs ORDER BY id DESC LIMIT 5")->result_array();
}
public function getForum($category)
{
return $this->db->query("SELECT * FROM forum WHERE category = $category ORDER BY id DESC LIMIT 5")->result_array();
}
function viewnews($id) {
return $this->db->query("SELECT u.id, u.podcategory,u.title, u.content, d.title AS d_title FROM forum u INNER JOIN category_forum d ON u.category = d.id WHERE d.title=$id")->result_array();
}
function setblog($blog_title,$blog_body){
$this->db->query("INSERT INTO blog (blog_title,blog_body) VALUES ('$blog_title','$blog_body')");
}
function getblog() {
return $this->db->query("SELECT id,blog_title,blog_body,blog_time,answer FROM blog WHERE activation=1 ORDER BY id DESC LIMIT 7")->result_array();
}
function getblogfor() {
return $this->db->query("SELECT id,blog_title,blog_body,blog_time FROM blog WHERE activation=0 ORDER BY id DESC LIMIT 7")->result_array();
}
function setblogfor($id,$answer){
$this->db->query("UPDATE blog SET answer = '$answer',activation='1' WHERE id='$id'");
}
}
?>