Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
multiple search
  • how to create multiple search by name,email,address,zip in fuelphp.

    can i use orm?
  • philipptempelphilipptempel
    Accepted Answer
    Yes you can.

    Look into the docs for the ORM and its query builder to find out about how to do it in your particular case.
  • Thank Mr.philipptempel.

    I could be created multiple search by using Custom SQL, but when i create pagination for that i got error like the following

    "Call to undefined method Fuel\Core\Database_Query::rows_offset()"

    My code is the following:

    $search_query = "SELECT * FROM customers WHERE hotel_code = 1";

    if ( ! empty($name))
    {
    $search_query .= " AND customer_name LIKE '%".$name."%'";
    }

    if ( ! empty($phone))
    {
    $search_query .= " AND customer_email LIKE '%".$phone."%'";
    }

    $data['results'] = \DB::query($search_query)->as_object('\Customer\Model_Customer')->execute();

    $total = count($data['results']);
    $config = array(
    'uri_segment' => 'page',
    'per_page' => 20,
    'total_items' => $total,
    );

    $pagination = \Pagination::forge('mypagination', $config);
    $data['search_results'] =\DB::query($search_query)
    ->as_object('\Customer\Model_Customer')
    ->rows_offset($pagination->offset)
    ->rows_limit($pagination->per_page)
    ->execute();

    $this->template->content = \View::forge('customer::customer/search_result', $data);

    i tried change rows_offset to offset and rows_limit to limit but i got the same error.

    How can i solve that error?
  • rows_offset() is an ORM method, you're constucting a query by hand, you should not do that, it's complex, difficult to maintain, and the way you are doing it, VERY insecure.

    Read up on ORM crud queries, plenty of select examples in the docs...
  • I do so:

    $where = array();

    $name = Input::get('name');
    $email = Input::get('email');
    $address = Input::get('address');
    $zip = Input::get('zip');

    $name and $where[] = array('name','=',$name);
    $email and $where[] = array('email','=',$email);
    $address and $where[] = array('address','=',$address);
    $zip and where[] = array('zip','=',$zip);

    $query = Model_Customer::query();

    count($where)===0 or $query = $query->where($where);

    $pagination = Pagination::forge('default',array(
        'total_items' = $query->count(),
        'per_page' = 10,
        'uri_segment' = 'page',
        'num_links' = 10,
        'show_first' = true,
        'show_last' = true,
    ));

    $data['search_result'] = $query()
        ->limit($pagination->per_page)
        ->offset($pagination->offset)
        ->get();

    $this->template->content = \View::forge('customer::customer/search_result', $data);

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion