Welcome Guest, Not a member yet? Register   Sign In
unable to use active record
#1

[eluser]kikz4life[/eluser]
i used this code to replace my old standard php code


Code:
$sql = 'Delete from '.$crudTableName.' where role_id = '.$crudColumnValues['id'];
mysql_query( $sql );

convert to CI

$this->db->delete('sec_role', array('role_id' => $crudColumnValues['id'])); <-- dont work, dont know why

this is the code which i want to convert to CI and used the active record
Code:
case $crudConfig['create']:
                $sql = 'insert into '.$crudTableName.'(';
                $sql .= implode(',',$crudColumns);
                $sql .= ')VALUES(';
                $sql .= implode(',',$crudColumnValues);
                $sql .= ')';
                mysql_query( $sql );
                break;
            case $crudConfig['update']:
                $sql = 'update '.$crudTableName.' set ';
                foreach($crudColumns as $key => $value){ $updateArray[$key] = $value.'='.$crudColumnValues[$key]; };
                $sql .= implode(',',$updateArray);
                $sql .= ' where role_id = '.$crudColumnValues['id'];
                mysql_query( $sql );
                break;
            case $crudConfig['delete']:
                
                
                $sql = 'Delete from '.$crudTableName.' where role_id = '.$crudColumnValues['id'];
                mysql_query( $sql );
                break;

no error where found by firebug and i tried to echo $crudColumnValues and the result is the correct id i want to delete. Help anyone. Dont know why it wont work.. Sad

thanks in advance
#2

[eluser]flaky[/eluser]
for
Code:
$sql = 'Delete from '.$crudTableName.' where role_id = '.$crudColumnValues['id'];
do it like this
Code:
$this->db->where('role_id', $crudColumnValues['id']);
$this->db->delete($crudTableName);
#3

[eluser]flaky[/eluser]
for insert
Code:
//For insert
//Keep in mind that your array $crudColumnValues should be structured like this
//example
//$crudColumnValues['column1'] = 'value 1';
//$crudColumnValues['column2'] = 'value 2';
case $crudConfig['create']:
    $this->db->insert($crudTableName, $crudColumnValues);
    break;
#4

[eluser]flaky[/eluser]
for update
Code:
//For update
//Keep in mind that your array $crudColumnValues should be structured like this
//example
//$crudColumnValues['column1'] = 'value 1';
//$crudColumnValues['column2'] = 'value 2';
case $crudConfig['update']:
    $this->db->where('role_id', $crudColumnValues['id']);
    $this->db->update($crudTableName, $crudColumnValues);
    break;




Theme © iAndrew 2016 - Forum software by © MyBB