使用函数在Postgres中显示Select Count中的数据


Display data from a Select Count in Postgres with function

我试图在这里进行选择,但我们没有显示任何数据,如下所示,我需要在postgreme中的表上进行选择计数,它显示有多少记录要选择这个字段,而不是null,只是有多少记录非零。已经有一个类似的函数,但它有所有的记录,我不会这样做,只告诉记录非零。代码如下:这就是为用户显示的内容:

    <?php
    require_once 'chklogado.php';
    require_once 'model.php';
    $funcao = $_SESSION['funcao'];
    $model = new Model();
    $cont = array();
    $cont['promocoes'] = $model->get_count('promocoes');
    $cont['promocoes_novos'] = $model->get_promonovos('promocional');
    $cont['seminovos'] = $model->get_count('seminovos');
    $cont['noticias'] = $model->get_count('noticias');
    $cont['news'] = $model->get_count('contatos_newsletter');
    $cont['banner'] = $model->get_count('banner');
    $cont['pwd'] = $model->get_count('passwd');
    ?>
    <ul>
   <?php if($funcao<4 ) { // todos menos marketing?>
   <li class="inovos"><a href="promocoes-novos.php" title=""><span>Promoções de Carros Novos</span></a><span class="numberMiddle"><?php echo get_value($cont, 'promocoes_novos'); ?></span></li>
   <?php } //endif ?>
   <?php if($funcao==1 or $funcao==3 ) { // administrador e vendas ?>
   <li class="iOrders"><a href="lista-promocoes.php" title=""><span>Promoções</span></a><span class="numberMiddle"><?php echo get_value($cont, 'promocoes'); ?></span></li>
   <?php } //endif ?>
   <?php if($funcao==1 or $funcao==4 ) { // administrador e marketing ?>
   <li class="iStat"><a href="lista-banners.php" title=""><span>Cadastro Banners</span></a><span class="numberMiddle"><?php echo get_value($cont, 'banner'); ?></span></li>
   <?php } //endif ?>
   <?php if($funcao<4 ) { // todos menos marketing?>
   <li class="iMes"><a href="lista-seminovos.php" title=""><span>Add Seminovo</span></a><span class="numberMiddle"><?php echo get_value($cont, 'seminovos'); ?></span></li>
   <?php } //endif ?>
   <?php if($funcao==1 or $funcao==4 ) { // administrador e marketing ?>
   <li class="inoticias"><a href="lista-noticias.php" title=""><span>Notícias</span></a><span class="numberMiddle"><?php echo get_value($cont, 'noticias'); ?></span></li>
   <?php } //endif ?>

   <?php if($funcao==1 or $funcao==4 ) { // administrador e marketing ?>
   <li class="iNews"><a href="lista-newsletter.php" title=""><span>Mala direta</span></a><span class="numberMiddle"><?php echo get_value($cont, 'news'); ?></span></li>
   <?php } //endif ?>

   <?php if($funcao==1 ) { // administrador  ?>
   <li class="iUser"><a href="lista-usuarios.php" title=""><span>Admin Usuário</span></a><span class="numberMiddle"><?php echo get_value($cont, 'pwd'); ?></span></li>
   <?php } //endif ?>
</ul>

这就是进行选择的功能:

function get_count($table = ''){
    return $table ? pg_fetch_result($this->get_all($table, '', 'COUNT(*) as total'), 0, 'total') : 0;
}
function get_promonovos($table = ''){
    //return $result=pg_query($sql="SELECT count(venda) FROM promocional where venda>0;");
    //$sql=("select * from promocional where venda is not null;");
    //$resultado = pg_fetch_array($sql);
    //return pg_free_result($resultado);
    //$data = pg_Fetch_Object($result, 0);
    //return pg_fetch_array($result, $sql);
    //return pg_free_result($result);
    $result = pg_query("select count(*) from promocional where venda is not null;");
    $count = pg_fetch_result($result);
}

你可以看到函数"get_Count"创建帐户,这个函数"get_promonovos"是我需要在这里显示选择但测试的结果,否则他会返回null或"Release id#"。有人知道什么是可能的吗?

设法解决的只是像这样更改函数:

$sql = "SELECT COUNT(venda) AS TOTAL FROM promocional WHERE venda is not null";
$query = pg_query($sql);
while($row = pg_fetch_array($query)){
$total = $row["total"];
}
echo $venda. $total;

Count(*)可能较慢

$sql="从TableName中选择*";

$res=pg_query($sql);

$count=pg_num_rows($res)

echo"行数="$计数