从模型返回单个变量值(字符串)并将其填入文本视图字段 - Codeigniter

I have the following Model, Controller and view. Using PHP Point of Sale 11.3. I'm trying to take the max value in a DB column and display it in a text field in view.

Model:

function getmax()
{
    $query = $this->db->query("SELECT max(item_id) FROM phppos_items");
    return $query->row();
}

Controller:

function view()
{   
    $data['max_id']=$this->Item->getmax();      
    $this->load->view("items/form",$data);
}

View:

<?php 

    echo $max_id; //line 16. Error Here.

    echo form_input(array(
                        'name'=>'item_number',
                        'id'=>'item_number',
                        'value'=>set_value('item_number',$max_id)) //is this right??
                    );
?>

Am getting two errors when execution.

A PHP Error was encountered
Severity: 4096
Message: Object of class stdClass could not be converted to string
Filename: items/form.php
Line Number: 16

A PHP Error was encountered
Severity: Warning
Message: htmlspecialchars() expects parameter 1 to be string, object given
Filename: helpers/form_helper.php
Line Number: 625

I'm getting the max_id without any issues when used as dropdown in view.

<?php echo form_dropdown('max_id',$max_id);?>

But I need this value to be filled in default in the form text field. Thanks in advance.

It should have been like this

Model

function getmax()
{
    $query = $this->db->query("SELECT max(item_id) as MaxID FROM phppos_items");
    return $query->row();
}

Controller

function view()
{   
    $data['row']=$this->Item->getmax();      
    $this->load->view("items/form",$data);
}   

View

$options['name']    =   'item_number';
$options['id']      =   'item_number';
$options['value']   =   set_value('item_number',$row->MaxID);

echo form_input($options);  

You see i am using row

use in your view:

$max_id->max

and in your sql in the model change it to:

"SELECT max(item_id) AS max FROM phppos_items"

See if that works