| 
									
										
										
										
											2012-04-08 00:36:38 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	class Cat extends CI_Model { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		function __construct() | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			// Call the Model constructor
 | 
					
						
							|  |  |  | 			parent::__construct(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		function update($result) { | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 			$this->db->where('radio', $result['radio']);  | 
					
						
							|  |  |  | 			$query = $this->db->get('cat'); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			if ($query->num_rows() > 0) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				// Update the record
 | 
					
						
							|  |  |  | 				foreach ($query->result() as $row) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					$radio_id = $row->id; | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					$data = array( | 
					
						
							|  |  |  | 					   'frequency' => $result['frequency'], | 
					
						
							|  |  |  | 					   'mode' => $result['mode'] | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					$this->db->where('id', $radio_id); | 
					
						
							|  |  |  | 					$this->db->update('cat', $data);  | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				// Add a new record
 | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				$data = array( | 
					
						
							|  |  |  | 				   'radio' => $result['radio'], | 
					
						
							|  |  |  | 					'frequency' => $result['frequency'], | 
					
						
							|  |  |  | 					'mode' => $result['mode'] | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				$this->db->insert('cat', $data);  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 		function status() { | 
					
						
							| 
									
										
										
										
											2012-04-08 20:17:14 +08:00
										 |  |  | 			//$this->db->where('radio', $result['radio']); 
 | 
					
						
							|  |  |  | 			$query = $this->db->get('cat'); | 
					
						
							| 
									
										
										
										
											2012-04-08 00:36:38 +08:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-04-08 23:47:18 +08:00
										 |  |  | 			return $query; | 
					
						
							| 
									
										
										
										
											2012-04-08 00:36:38 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-08 20:17:14 +08:00
										 |  |  | 		/* Return list of radios */ | 
					
						
							|  |  |  | 		function radios() { | 
					
						
							|  |  |  | 			$this->db->select('id, radio'); | 
					
						
							|  |  |  | 			$query = $this->db->get('cat'); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			return $query; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-11-14 04:14:39 +08:00
										 |  |  | 		function delete($id) { | 
					
						
							|  |  |  | 			$this->db->where('id', $id); | 
					
						
							|  |  |  | 			$this->db->delete('cat');  | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-04-08 20:17:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-08 00:36:38 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | ?>
 |