Welcome Guest, Not a member yet? Register   Sign In
$this->db->where_in
#5

[eluser]mrliam69[/eluser]
I have created a for each loop to create my string.
Code:
$ValidDealersForUser =     "SELECT DealerLogNumber
                        FROM `tblDealerInfo`
                        WHERE `DealerCode` = (
                        SELECT `UserDealerCode`
                        FROM `fa_user_profile`
                        WHERE id = ? )";
                        
        $VDFUquery = $this->db->query($ValidDealersForUser,$this->db_session->userdata('id'));
    
        $MAX = $VDFUquery->num_rows();    
        $ValidDealers = "";
        $i=1;
        foreach ($VDFUquery->result_array() as $row)
{
           $ValidDealers = $ValidDealers.$row['DealerLogNumber'];
        if ($i==$MAX)
              $ValidDealers=$ValidDealers;
        else
              $ValidDealers=$ValidDealers.",";
          $i++;

}

this creates a string called $ValidDealers which in my test echo returns 5,6

so db part now becomes

Code:
$this->db->where_in('VehServicingDealer',array(($ValidDealers)));

using the $ValidDealers in the array

but the sql generated is

SELECT * FROM (`tblVehicles`) WHERE `VehLog` = '3390' AND `VehServicingDealer` IN ('5,6')

which is incorrect as the end bit should be IN (5,6) without the apostrophes?

How can I strip the apostrophes ?


Messages In This Thread
$this->db->where_in - by El Forum - 11-09-2008, 12:32 PM
$this->db->where_in - by El Forum - 11-09-2008, 12:43 PM
$this->db->where_in - by El Forum - 11-09-2008, 02:34 PM
$this->db->where_in - by El Forum - 11-09-2008, 07:25 PM
$this->db->where_in - by El Forum - 11-09-2008, 07:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB