Welcome Guest, Not a member yet? Register   Sign In
Problem with active record database query
#1

[eluser]umbongo[/eluser]
Code:
$columns = array('column 1', 'column 2', 'column 3')

$q = $this->db->select($columns);

this returns the following error;

Code:
A Database Error Occurred
Error Number: 1054

Unknown column 'column' in 'field list'

SELECT `column` 1, `column` 2, `column` 3

How do i fix this so that it properly does 'SELECT `column 1`, `column 2`, `column 3`'??
#2

[eluser]cahva[/eluser]
Dont use spaces in your field names? No.. Let me rephrase that. Dont use spaces in your field names. Smile
#3

[eluser]umbongo[/eluser]
Why? mysql supports them doesn't it?
#4

[eluser]zhangshjin[/eluser]
No.. Let me rephrase that. Dont use spaces in your field names.
#5

[eluser]cahva[/eluser]
[quote author="umbongo" date="1291015332"]Why? mysql supports them doesn't it?[/quote]
Even if it does support them, it doesnt mean you should use them. It will just make your life harder(you'll realise that atleast then when you want to use the returned result). Just replace those spaces with underscores. Trust me Smile
#6

[eluser]umbongo[/eluser]
OK, well if i must change them, then how do i reference one side of an array.

When they were both the same I used the array for both database lookup and table creation.

So i guess i will now need an array;

Code:
$columns = array(
'column 1'=>'column_1',
'column 2'=>'column_2',
'column 3'=>'column_3',
);
Now, how can i reference one side of it? I know in a foreach loop you can do
Code:
foreach($columns AS $column => $column_db):
But how can i do this outside of a foreach loop??
#7

[eluser]Abdul Malik Ikhsan[/eluser]
maybe like this Smile
Code:
foreach($records as $keyrec=>$rowrec)
   {
        foreach($columns as $column=>$column_db)
        {
              echo $rowrec[$column_db];
        }
        echo "<br />";
   }
#8

[eluser]umbongo[/eluser]
??
your response has lost me.
I am trying to get one side (all values either before or after '=>') as an array, other than in a foreach loop.
#9

[eluser]Akinzekeel[/eluser]
Try array_keys or array_values




Theme © iAndrew 2016 - Forum software by © MyBB