Welcome Guest, Not a member yet? Register   Sign In
Using select_min()
#1

[eluser]sore eyes[/eluser]
hi, I want to pull the first record from a database. I am using select_min() to do this.

For the model:

Code:
function getMinShopID()
    {
    $this->db->select_min('shop_id');
    $data = $this->db->get('shop');
    return $data;
    }

For the controller:
Code:
function getFirstRecord()
    {
        $shop_id = $this->MShops->getMinShopID();
        echo "shop id is ".$shop_id;
    }

Produces an error:
A PHP Error was encountered

Severity: 4096

Message: Object of class CI_DB_mysql_result could not be converted to string

Filename: controllers/welcome.php

Line Number: 63
shop id is

Any ideas please and a merry xmas
#2

[eluser]cfraz[/eluser]
Does it work if you change this
Code:
$data = $this->db->get('shop');

to this?
Code:
$data = $this->db->get('shop_id');

Why not use limit(1) instead of select_min()? That way you only read 1 row of the table rather than all of them.
#3

[eluser]sore eyes[/eluser]
hi cfraz, thanks for responding. 'shop' is the name of the table, rather than shop_id which is the name of a field, so changing it does not work.

What I want to do is show the details of each record on one page and to be able to cycle through them, using buttons 'goFirst', 'goNext', 'goPrevious' and 'goLast'. So I thought of using the id of each record for this. Using 'limit' of 1 works for the first record, but it cannot be used for the other records.




Theme © iAndrew 2016 - Forum software by © MyBB