radiations3 Posted April 8, 2012 Share Posted April 8, 2012 Hello, I am using the following code to get values from the database $age = $this->security->xss_clean($this->input->post('select')); // assigning Selected Age difference value to a variable $age $place = $this->security->xss_clean($this->input->post('select2')); // assigning Selected Age difference value to a variable $age $this->db->where('Place', $place); $query = $this->db->get('person'); // Select * from person where Place = $place return $query->result(); // returning result of queries but when i put restriction on it on the behalf of dates to calculate the results as per age limits then its not doing the filteration and displays all the records and if not value exist then return an error foreach($results as $row) { $date_db = $row->Dob; // Getting the date of the person returned from the database $date_current = date('d-m-Y'); // Getting the current date from the system $diff = abs(strtotime($date_current) - strtotime($date_db)); // Calculating the differences between two dates $years = floor($diff / (365*60*60*24)); // Storing the resultant age in the variable if ( $years>=$comp1 && $years<$comp2) // Comparing the results if less than or greater than to certain AGE limits return $query->result(); // returning result of queries else return false } [/code] Kindly let me know what is wrong with my code or how to return values as per filteration i seek for I'll be very thankful to YOU!!! Quote Link to comment https://forums.phpfreaks.com/topic/260563-question-regarding-mvc-codeignitor/ Share on other sites More sharing options...
scootstah Posted April 8, 2012 Share Posted April 8, 2012 I'm not sure I totally understand your question, but I think you want to select rows from a database, loop through them, and return modified values. Is that right? Currently you are returning the result inside the foreach loop on every iteration. Therefore you are ignoring any modifications and just returning the original result set. Instead you'll need to build a new array of results, add the modified values on each iteration, and then return that afterwards. On an unrelated note, you don't need to run input through the xss_clean method from the security class. You can simply use the second parameter on input's post method to run xss_clean. // this... $age = $this->security->xss_clean($this->input->post('select')); $place = $this->security->xss_clean($this->input->post('select2')); // ...is the same as this... $age = $this->input->post('select', true); $place = $this->input->post('select2', true); Quote Link to comment https://forums.phpfreaks.com/topic/260563-question-regarding-mvc-codeignitor/#findComment-1335423 Share on other sites More sharing options...
radiations3 Posted April 10, 2012 Author Share Posted April 10, 2012 yes you are riught and thanx for helping me out i got the idea now..... Quote Link to comment https://forums.phpfreaks.com/topic/260563-question-regarding-mvc-codeignitor/#findComment-1336038 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.