Welcome Guest, Not a member yet? Register   Sign In
Binding SQL arguments. A bit complex situation.
#1

[eluser]behnampmdg3[/eluser]
Hey igniters;

Hopefully I find answer to this quesiton here. I wrote some code to dynamically bind data as below:
Code:
public function search_results($data, $record_start=0,$number_of_records=4,$next_prev_sign='>', $order=' ASC ')
{
  $conditions = $values = array();
  foreach($data as $val=>$row)
   {
    $conditions[] = $val." = ?";
   }
  foreach($data as $val=>$row)
   {
    $values[] = $row;
   }
  if ($conditions)
   {
    $this->where = " AND " . implode(" AND ", $conditions);
   }
  $sql = "SELECT q2.id,
      q2.code,
      q2.class,
      q2.category,
      q2.price,
      q2.production_date,
      q4.title AS STATUS
  FROM   (SELECT q1.id,
        q1.status,
        code,
        class,
        category,
        price,
        production_date
    FROM   products_table AS q1
    WHERE  q1.id  ".$next_prev_sign." ".$record_start."
    ".$this->where."
    ORDER  BY q1.id ".$order."
    LIMIT  ".$number_of_records.") AS q2
      INNER JOIN products_table AS q3
        ON q3.id = q2.id
      JOIN products_status AS q4
     ON q4.id = q3.status ";
  $results = $this->db->query($sql, $values);
  return $results->result_array();
}
This produces
Code:
SELECT q2.id,
               q2.code,
               q2.class,
               q2.category,
               q2.price,
               q2.production_date,
               q4.title AS STATUS
        FROM   (SELECT q1.id,
                       q1.status,
                       code,
                       class,
                       category,
                       price,
                       production_date
                FROM   products_table AS q1
                WHERE  q1.id   >  0
                 AND class = '1' AND category = 'C'
                ORDER  BY q1.id ASC
                LIMIT  20) AS q2
               INNER JOIN products_table AS q3
                       ON q3.id = q2.id
               JOIN products_status AS q4
                 ON q4.id = q3.status
Now my problem is I don't want CI to add single quotes to numeric arguments! How can I active that with the code above? For example AND class = '1' will change to AND class = 1

Please tell me it's possible haha great thanks forum.


Messages In This Thread
Binding SQL arguments. A bit complex situation. - by El Forum - 05-25-2013, 08:39 PM
Binding SQL arguments. A bit complex situation. - by El Forum - 05-25-2013, 10:09 PM
Binding SQL arguments. A bit complex situation. - by El Forum - 05-26-2013, 12:48 AM
Binding SQL arguments. A bit complex situation. - by El Forum - 05-28-2013, 08:30 AM
Binding SQL arguments. A bit complex situation. - by El Forum - 05-28-2013, 01:29 PM



Theme © iAndrew 2016 - Forum software by © MyBB