Welcome Guest, Not a member yet? Register   Sign In
ok , I know I am being dumb..... but I can't get this query to work.....
#1

[eluser]codeamanny[/eluser]
I have been reading through the user manual and it keeps saying that I need to use foreach, however I only want a single result from a table.

Heres the prob...

I used active record to pull some records from my db. Now when I do a var_dump of the $query->result(), I can see the following:

Code:
array(6) { [0]=>  object(stdClass)#13 (3) { ["report_id"]=>  string(3) "125" ["created_date"]=>  string(19) "2007-10-01 00:00:00" ["receipent_company"]=>  string(15) "Yum Yum  ltd" } [1]=>  object(stdClass)#14 (3) { ["report_id"]=>  string(3) "205" ["created_date"]=>  string(19) "2007-02-27 00:00:00" ["receipent_company"]=>  string(15) "Yum Yum  ltd" } [2]=>  object(stdClass)#15 (3) { ["report_id"]=>  string(3) "213" ["created_date"]=>  string(19) "2007-03-01 00:00:00" ["receipent_company"]=>  string(15) "Yum Yum  ltd" } [3]=>  object(stdClass)#16 (3) { ["report_id"]=>  string(3) "233" ["created_date"]=>  string(19) "2007-09-27 00:00:00" ["receipent_company"]=>  string(15) "Yum Yum  ltd" } [4]=>  object(stdClass)#17 (3) { ["report_id"]=>  string(3) "310" ["created_date"]=>  string(19) "2007-05-05 00:00:00" ["receipent_company"]=>  string(15) "Yum Yum  ltd" } [5]=>  object(stdClass)#18 (3) { ["report_id"]=>  string(3) "442" ["created_date"]=>  string(19) "2007-09-17 00:00:00" ["receipent_company"]=>  string(15) "Yum Yum  ltd" } }

I want to put the company name at the top of the report form, however it seems to be impossible to refer to it.
#2

[eluser]Jameson.[/eluser]
Example from the User Guide, Database section, quick start page
Standard Query With Single Result
Code:
$query = $this->db->query('SELECT ... FROM ... WHERE ... LIMIT 1');

$row = $query->row();
echo $row->receipent_company;
Standard Query With Single Result (Array version)
Code:
$query = $this->db->query('SELECT ... FROM ... WHERE ... LIMIT 1');

$row = $query->row_array();
echo $row['receipent_company'];
#3

[eluser]codeamanny[/eluser]
thanks for that, I must be doing something else wrong as its giving me warnings. At least I know where to look now..
#4

[eluser]xwero[/eluser]
the result method returns an object that is why you see stdClass appear. It's the php base class.




Theme © iAndrew 2016 - Forum software by © MyBB