• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using a table name as a variable in Active Record Query

#1
[eluser]Unknown[/eluser]
I am an ASP.Net developer and I'm learning PHP/Code Igniter. I like it so far..BUT:

There is probably a very simple answer to this question. I have looked around for the solution, but all examples that I have seen do not use variables as I do here.

This works:
Code:
$query = $this->db->get('my_table');

This doesn't:
Code:
$query = $this->db->get($tbl);

In my model, I have a method that takes $tbl as an argument:
Code:
public function getAll($tbl)

I am passing in the name from my controller as such:

Code:
$data['mlist'] = $this->my_model->getAll('my_table');

The error I get is "Message: Invalid argument supplied for foreach()"

But the same foreach loop works when I "hard code" the table name in. I just don't see how this isn't working.

Anyway, thanks in advance for any help.


Messages In This Thread
Using a table name as a variable in Active Record Query - by El Forum - 07-15-2012, 07:32 AM
Using a table name as a variable in Active Record Query - by El Forum - 07-15-2012, 07:35 AM
Using a table name as a variable in Active Record Query - by El Forum - 07-15-2012, 07:47 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.