表A中字段teble有两条数据
查询A表table字段并统计数目获得了字段名为num值为2
代码:$temp=$data->query($sql)
现在我要显示这个统计echo $temp[0]['num']  但是空的
然后我用print_r($temp)显示的是Array ( [] => Array ( [num] => 1 ) )
为什么它没索引了?重装之后就这样了...是我的phpini哪配置的问题吗?
对了,以前用的php版本是5.2.9  重装后用的是5.2.13$data的query方法是:function query($sql){
  $result = mysql_query($sql,$this->con);
  while ($row = mysql_fetch_assoc($result)){
   $array[$i++] = $row;
  }

解决方案 »

  1.   


    function query($sql)//返回多个。
    {
    $rss=array();
    $result=mysql_query($sql);
    if(mysql_num_rows($result)!=0)
    {

    while($row=mysql_fetch_assoc($result))
    {
    $rss[]=$row;
    }

    }
    return $rss;
    }
      

  2.   

    <?php 
    function query($sql){
        $result = mysql_query($sql,$this->con);
        return mysql_fetch_assoc($result);
    }
    ?>
      

  3.   

    这样就可以了
    function query($sql){
      $result = mysql_query($sql,$this->con);
      while ($row = mysql_fetch_assoc($result)){
       $array[] = $row;
      }