将结果重新调整为字符串

时间:2014-09-11 20:49:18

标签: php mysql codeigniter

我目前有以下查询给出了int(0)的结果我怎么能这样做才能获得0的结果?

代码:

public function check_manufacturer_id($manufacturer_id)
{
    $table  = $this->_table_products_manufacturers;
    $query  = $this->db->query("SELECT $table.id FROM $table WHERE $table.id = $manufacturer_id");
    $result = $query->num_rows();

    return $result;
}

1 个答案:

答案 0 :(得分:0)

您可以将类型转换放在变量名之前,如return (string)$result;

使用您的代码:

public function check_manufacturer_id($manufacturer_id)
{
    $table  = $this->_table_products_manufacturers;
    $query  = $this->db->query("SELECT $table.id FROM $table WHERE $table.id = $manufacturer_id");
    $result = $query->num_rows();

    return (string)$result;
}