Welcome Guest, Not a member yet? Register   Sign In
$this->db->select_max()
#1

[eluser]borgir[/eluser]
Hey there!
Anyone knows how can I get the result of the following query:

Code:
$this->db->select_max('field');
$query = $this->db->get($db_name);

?

I've tried:
$query->result();
foreach ...
But without success.
Thks!
#2

[eluser]bretticus[/eluser]
a max() on one field should never return more than one result. See "row()" under Generating Query Results.
#3

[eluser]borgir[/eluser]
Found it:

Code:
foreach ($query->result() as $row) {
   echo $row->field;
}

Source:
http://ellislab.com/codeigniter/user-gui...sults.html

Cheers!
#4

[eluser]borgir[/eluser]
[quote author="bretticus" date="1254345809"]a max() on one field should never return more than one result. See "row()" under Generating Query Results.[/quote]

Thks bretticus!
Actually thats how I've solved it.
Cheers!
#5

[eluser]bretticus[/eluser]
[quote author="borgir" date="1254345964"]
Thks bretticus!
Actually thats how I've solved it.
Cheers![/quote]

You are certainly welcome. Just a little note. You will not require a for loop for this. You can call $query->row() directly.
#6

[eluser]n0xie[/eluser]
Or use chaining (if you use PHP5)
Code:
$this->db->select_max('field');
echo $this->db->get($db_name)->row()->field;




Theme © iAndrew 2016 - Forum software by © MyBB