Welcome Guest, Not a member yet? Register   Sign In
Display query row without looping through results?
#1

[eluser]chr1831[/eluser]
Is it possible to display a query row (lets say row 2) by doing something like $query->display_row(2)->title? or am I stuck making 3 database calls to get direct query access?

Thanks,
Chr1831
#2

[eluser]WanWizard[/eluser]
What do you mean by "3 database calls"?

To get the title of row 2 a simple "SELECT title FROM table WHERE row = 2" would suffice.

Or even this would be only one query:
Code:
$query = $this->db->query("SELECT * FROM table");
$row = $query->row(2);
echo $row->title;
#3

[eluser]chr1831[/eluser]
Thanks for the reply, but it appears that I have ran into a brick wall.

My model returns $query->result(); and my view needs to pull the second record out. $data->row(2) won't return correctly since it is no longer an object.

Thanks,
Chr1831
#4

[eluser]WanWizard[/eluser]
As per the manual, $query->result() returns an array of objects, or an empty array if no results were found.

So if you assign the return value of your model method to $data, the correct syntax would be
Code:
echo $data[1]->title;
#5

[eluser]chr1831[/eluser]
Ahhh, thanks for the help.

Thanks,
Chr1831




Theme © iAndrew 2016 - Forum software by © MyBB