Welcome Guest, Not a member yet? Register   Sign In
Search multiple coloumn with multiple field
#5

[eluser]harris_priambudi[/eluser]
[quote author="Tominator" date="1338990430"]You can do that using Active Record:

Code:
$this->db->from('car_data');

if ( ! empty( $car_name ))
$this->db->where('car_name', $car_name);


if ( ! empty( $car_colour ))
$this->db->where('car_colour', $car_colour);


if ( ! empty( $car_horsepower ))
$this->db->where('car_horsepower', $car_horsepower);

$query = $this->db->get();

Or you can try to code your own, like that:

Code:
if ( ! empty( $car_name ))
$array[] = ('car_name = '. $car_name);

if ( ! empty( $car_colour ))
$array[] = ('car_colour = '. $car_colour);

if ( ! empty( $car_horsepower ))
$array[] = ('car_horsepower = '. $car_horsepower);

$where = implode(' or ', $array);

$query = "SELECT * FROM car_data WHERE ". $where;

I hope this helps Smile I'm thinking about other solutions ...[/quote]

Wow thx for the answer, I understand the logic for this problem Big Grin
but I confuse about this code
Code:
$array[]
its error when im compile..


Messages In This Thread
Search multiple coloumn with multiple field - by El Forum - 06-06-2012, 06:27 AM
Search multiple coloumn with multiple field - by El Forum - 06-06-2012, 06:30 AM
Search multiple coloumn with multiple field - by El Forum - 06-06-2012, 06:36 AM
Search multiple coloumn with multiple field - by El Forum - 06-06-2012, 06:47 AM
Search multiple coloumn with multiple field - by El Forum - 06-06-2012, 07:30 AM
Search multiple coloumn with multiple field - by El Forum - 06-06-2012, 07:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB