0

我正在尝试在这里进行选择,但我们没有显示任何数据,如下所示,我需要在 postgre me 中的表上进行选择计数,其中显示要选择该字段的非空记录数,有多少非零记录。已经有一个类似的功能,但是它具有所有记录,我不会这样做以仅告诉记录非零。代码如下: 这是为用户显示的内容:

    <?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 #”。有谁知道可以是什么?

4

2 回答 2

1

设法解决只是改变这样的功能:

$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;
于 2013-07-23T13:42:01.870 回答
-1

计数 (*) 可能会更慢

$sql = "从表名中选择 *";

$res = pg_query($sql);

$count = pg_num_rows($res);

echo "# of Rows = ".$count;

于 2014-04-29T10:08:44.563 回答