Php 从“accounts”中选择COUNT(*),其中role=“engineer”使用symfony1.4获取总行数
嗨,我在从表帐户获取所有数据时遇到问题,我想使用WHERE从表帐户获取数据的总数。让我们从表accounts中假设,其中role=engineer。字段role=engineer中的所有行总数将得到。我在这上面使用symfony框架 下面是我的控制器Php 从“accounts”中选择COUNT(*),其中role=“engineer”使用symfony1.4获取总行数,php,mysql,symfony-1.4,Php,Mysql,Symfony 1.4,嗨,我在从表帐户获取所有数据时遇到问题,我想使用WHERE从表帐户获取数据的总数。让我们从表accounts中假设,其中role=engineer。字段role=engineer中的所有行总数将得到。我在这上面使用symfony框架 下面是我的控制器 <?php class spFindRoleDetailAction extends sfAction{ function preExecute(){ } public function execute($request){
<?php
class spFindRoleDetailAction extends sfAction{
function preExecute(){
}
public function execute($request){
$this->setLayout('spLayout');
$this->setTemplate('sp/roleDetail');
$role = $request->getParameter('ro');
$this->roleDetail = AccountTable::getInstance()->getRoleDetail($role);
$this->roleCount = AccountTable::getInstance()->getCountDetail($role);
}
}
我的模块模板在这里查看代码
<div id="search-by-role-detail" data-role="page">
<div role="main">
<ul data-role="listview">
<li>
<a href="<?php echo url_for('@find-sp-role-page'); ?>" class="ui-btn ui-btn-icon-left ui-icon-nav-l center">
<h1>エンジニア<span class="header-result-count">(<?php echo $roleCount->count(); ?>)</span></h1>
</a>
</li>
<?php if(isset($roleDetail)): ?>
<?php foreach($roleDetail as $role): ?>
<li>
<a href="<?php echo $role->getSlug(); ?>"class="ui-btn ui-btn-icon-right ui-icon-list-r" data-transition="slide">
<?php if($role->getLogo() == NULL): ?>
<div class="middle v-image">
<img class="image-user" src="/images/sp/sample.png">
</div>
<?php else: ?>
<div class="middle v-image">
<img class="image-user" alt="<?php echo $role->getName(); ?>" src="http://img.creww.me/uploads/account/logos/<?php echo $role->getLogo(); ?>">
</div>
<?php endif; ?>
<div class="middle v-list">
<h3><?php echo $role->getName(); ?></h3>
<p><?php echo $role->getOverview(); ?></p>
</div>
</a>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
</div>
</div>
H1标记中的一个在那里有一个计数,我如何才能得到其中的总行数。我用的是一个错误的
有人能帮我吗??
非常感谢您的帮助
谢谢 如果count不起作用,那么您可以尝试类似的方法
public function getCountDetail($role)
{
$q = Doctrine_Query::create()
->from('[some table] a')
->where('a.role = ?', $role)
->select('COUNT(a.id)')
->execute(array(),Doctrine_Core::HYDRATE_SINGLE_SCALAR)
return $q;
}
在这种情况下,函数将返回一个表示找到的记录数的数字 你为什么认为计数法是错误的?请注意,在控制器中,您使用getRoleDetail方法,但您从模型中提供了getCountDetail方法。我更新了我的帖子。。错误的部分是将显示的总行数是错误的确定我将尝试此方法如何处理Doctrine_查询我将使用此方法?返回$this->createQuery'a'??它是一样的吗?你使用的是条令1.4还是条令2.x?使用symfony 1.4我的意思是条令也是1.4如果使用条令表对象也是一样的。看看这个例子,你的代码不工作,找不到类帐户
public function getCountDetail($role)
{
$q = Doctrine_Query::create()
->from('[some table] a')
->where('a.role = ?', $role)
->select('COUNT(a.id)')
->execute(array(),Doctrine_Core::HYDRATE_SINGLE_SCALAR)
return $q;
}