php - 如何使用事件记录从表中选择 *,其中 col1+col2=b

标签 php mysql codeigniter activerecord mariadb

如何使用 codeigniter 的事件记录运行 select * from table where col1+col2=b;。使用mysql

我尝试过但失败了

$this->db->where("col1 + col2",$b)->get("table")->result_array();

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '915087' at line 4

SELECT * FROM table WHERE a + b 25

最佳答案

You can do that how you were thought. Just fixed out your mistake follow the below code. Thanks. If it's useful please acknowledge it.

    $b = 25;
    $data = $this->db->where(array("(number1 + number2) = " => $b))->get("dummy_table")->result_array();
    echo "<pre>";
    print_r($data);



// output 
Array
(
    [0] => Array
        (
            [id] => 1
            [number1] => 10
            [number2] => 15
            [number3] => 25
        )

    [1] => Array
        (
            [id] => 2
            [number1] => 23
            [number2] => 2
            [number3] => 25
        )

    [2] => Array
        (
            [id] => 3
            [number1] => 9
            [number2] => 16
            [number3] => 25
        )

    [3] => Array
        (
            [id] => 4
            [number1] => 23
            [number2] => 2
            [number3] => 25
        )

)

关于php - 如何使用事件记录从表中选择 *,其中 col1+col2=b,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41237802/

相关文章:

mysql - 获取 UPDATE 的目标表时出错不可更新

PHP MySQL 表连接 - 仅回显标识符一次,然后是所有匹配的项目

php - Codeigniter 中关联数组变成了 where OR 子句

php - 如何使用 codeigniter 检索 mysql 数据库中的第一个单词 20

php - 在 Doctrine 中使用字符串、blob 或 clob 作为线程体?

javascript - 将当前位置坐标作为 GET 消息发送到服务器

php - ModX Revo : Query Multiple TVs?

php - 如何在 codeigniter 的模型中获取购物车的结果?

mysql - 如何在插入之前在mysql中创建触发器以将值与时间戳连接起来

php - Java EE vs PHP - 为什么这么多人认为 Java 更好?