php 选择最大代码点火器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8910671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 05:46:46  来源:igfitidea点击:

select max codeigniter

phpmysqlcodeigniter

提问by Augus

Im trying to get an max value with codeigniter from an table but it isnt working. This is the error i get:

我试图从表中使用 codeigniter 获取最大值,但它不起作用。这是我得到的错误:

Severity: 4096

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

Filename: database/DB_active_rec.php

Line Number: 427

严重性:4096

消息:类 CI_DB_mysql_result 的对象无法转换为字符串

文件名:数据库/DB_active_rec.php

行号:427

This is my function:

这是我的功能:

public function getPeriodeNummer($bedrijf_id) {
    $this->db->select_max('id');
    $this->db->where('bedrijf_id', $bedrijf_id);
    $result = $this->db->get('rapporten');

    $this->db->select('periode_nummer');
    $this->db->where('rapporten_id', $result);
    $query = $this->db->get('statistieken_onderhoud');

    $data = $query + 1;

    return $data;
}

What im trying to do is as followed:

我试图做的是如下:

  1. Select the highest idwhere bedrijf_id= $bedrijf_idfrom rapporten.
  2. Select the periode_nummerfrom statistieken_onderhoudwhere rapporten_id= the highest idi got from step 1.
  3. Add 1 to the periode_nummeri got from step 2 and returnthat number.
  1. 选择最高的idwhere bedrijf_id= $bedrijf_idfrom rapporten
  2. 选择periode_nummerfrom statistieken_onderhoudwhere rapporten_id=id我从步骤 1 中得到的最高值。
  3. 将 1 添加到periode_nummer我从第 2 步得到的return数字和那个数字上。

Thanks in forward for your help!

感谢您的帮助!

回答by stealthyninja

Try

尝试

public function getPeriodeNummer($bedrijf_id) {
    $this->db->select_max('id');
    $this->db->where('bedrijf_id', $bedrijf_id);
    $res1 = $this->db->get('rapporten');

    if ($res1->num_rows() > 0)
    {
        $res2 = $res1->result_array();
        $result = $res2[0]['id'];

        $this->db->select('periode_nummer');
        $this->db->where('rapporten_id', $result);
        $query = $this->db->get('statistieken_onderhoud');

        if ($query->num_rows() > 0)
        {
            $row = $query->result_array();
            $data['query'] = 1 + $row[0]['periode_nummer'];
        }

        return $data['query'];
    }

    return NULL;
}

回答by Santosh Pandey

Try this:

尝试这个:

    $this->db->select_max('display_sequence');
    $this->db->from('acl_menu');
    $query = $this->db->get();
    $r=$query->result();

Display Sequence is your column name & acl_menu is your table name.

Display Sequence 是您的列名,acl_menu 是您的表名。

回答by Maicol Romero

$this->db->select_max('id', 'max_id');
$query = $this->db->get('video_processing');

return $query->row();

try the above:

试试上面的:

回答by mirza

You can't use an object as a string. Use this:

您不能将对象用作字符串。用这个:

public function getPeriodeNummer($bedrijf_id) {
    $this->db->select_max('id');
    $this->db->where('bedrijf_id', $bedrijf_id);
    $result = $this->db->get('rapporten');

    $this->db->select('periode_nummer');
    $this->db->where('rapporten_id', $result);
    $query = $this->db->get('statistieken_onderhoud');
    // fetch first row in object
    $result = $query->row();
    $data = $result + 1;

    return $data;
}

回答by gustyaquino

I think the $queryvariable is holding a mysql result resource and it cannot be used as a String or in this case an Integer.

我认为该$query变量保存了一个 mysql 结果资源,它不能用作字符串或在这种情况下是整数。

You could try this way:

你可以试试这样:

$data = mysql_result($query,0) + 1;