Jump to content

Question Regarding MVC 'Codeignitor'


radiations3

Recommended Posts

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!!!

Link to comment
Share on other sites

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);

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.