Re: {CodeIgniter Kenya} Digest for codeigniter-kenya@googlegroups.com - 2 Messages in 1 Topic

13 views
Skip to first unread message

Nd'wex Common

unread,
Jan 13, 2012, 4:08:12 AM1/13/12
to codeigni...@googlegroups.com
Though this will increase the number of requests to the database, you could also the fields and construct the query in a loop before posting will reduce your code look fancy with possible bug increase more processing, but wont really make any difference in the final result.

$sql = "SELECT p.id,p.po_number,p.project,p.package_no,p.po_creation_date,p.atd_ex_works, p.etd_ex_works, p.customer,p.contractor,p.site,p.stock_code,p.part_number,p.line_items,p.unit_measure,p.order_qty, p.standing_qty, p.supplier, p.date_required, p.priority, p.archived FROM `purchase_orders` p WHERE deleted=0 AND archived=0 ";

$fields = $this->db->list_fields('table_name');
foreach ($fields as $field) {
     if ($field != "exclude_field")
        $q[] = "$field LIKE %$search_term%";
}

if (count($q) > 0) {
   $sql .= " and " . implode(" or ", $q);
}

$this->db->query($sql)->result();

Hope that was helpful

Peter Karunyu

unread,
Jan 17, 2012, 11:07:40 AM1/17/12
to codeigni...@googlegroups.com
Nice! So in the event that I add columns to the table, the new columns are automagically added to the search, clever :-)

And since almost all my tables have the same format of metadata columns, then excluding the un-necessary columns becomes easier.
--
Regards,
Peter Karunyu
-------------------

Reply all
Reply to author
Forward
0 new messages