简单的学说查询->一个特定的行和列

问题描述

| 我有一个名为
\"tax\"
的表,其中包含两列
\"id | tax_value\"
。我可以很好地列出带有2的表格。 现在我的问题是,当我只想拥有 一个特定的行和列的PHP代码?我不想在查询中!!! 例如:
column 2 (tax_value)

row 1.
该查询给了我一个数组,对吗?     

解决方法

        在TaxTable.class.php中:
public function getOneById($id)
{
    $q = Doctrine_Query::create()->select(\"t.tax_value\")
                                 ->from(\"tax t\")
                                 ->where(\"t.id = ?\",$id)
                                 ->fetchOne();
    return $q;
}
实际上:
public function executeTaxView(sfWebRequest $request)
{
    $this->tax = TaxTable::getInstance()->getOneById($request->getParameter(\"id\"));
    $this->forward404Unless($this->tax);
}
在taxViewSucess.php中:
  Tax Value: <b><?php echo $tax->getTaxValue();?></b>
    ,        当在select语句中获取具有单列的单行时,可以使用
Doctrine::HYDRATE_SINGLE_SCALAR
$total = Doctrine_Query::create()->from(\'Products p\')
        ->select(\'SUM(p.amount) as total\')
        ->where(\'p.category_id = ?\',$categoryId)
        ->fetchOne(array(),Doctrine::HYDRATE_SINGLE_SCALAR);
// $total is now a single value,eg. 12
该示例使用一个具有类别的假想产品表,并为特定类别选择产品数量。 在symfony中如何使用此查询取决于您的需要:在表类,模型类,操作等中。     ,        如果使用Doctrine_Query,则可以使用fetchOne捕获一行。此外,自从我使用了Doctrine 1以来,已经有些过时了,但是我几乎可以肯定,使用Doctrine_Query可以将字段选择列表设置为一列。     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...