我最近写的一个。也许对你说的问题有帮助的。。
<?php
/**
*@Purpose:类名tyd
*@Package Name:tyd_fy
*@Author:[email protected]
*@Modifications:修改记录
*No20040826_01:
*@See:(参考说明文档)
*@Method Name:属性说明null
*@Parameter:方法说明(根据$_get的客户等级、计量单位、线路、数量进行sql 查询)
*@Return:返回值(常规柜面托运价格,  等级门到门托运价,  等级门到位托运价,  托运货物包车价格 , *包车托运货物价格 )
*@Attribute/Variable Name:自定义null
*@Type:类型unfinde
**/
require_once "./global.php"; 
extract($_GET);
switch ($khdj) {
case "1" :
if ($jldw == "千克" or $jldw == "吨") {
$sql = "SELECT 
  `wl_dic_tyjj_bz`.`XL_ID`,
  `wl_dic_tyjj_bz`.`W_FIELD_1`,
  `wl_dic_tyjj_bz`.`W_FIELD_2`,
  `wl_dic_tyjj_bz`.`V_FIELD_1`,
  `wl_dic_tyjj_bz`.`V_FIELD_2`,
  `wl_dic_tyjj_bz`.`K_FIELD_3`,
  `wl_dic_tyjj_bz`.`K_FIELD_4`,
  `wl_dic_tyjj_bz`.`TYR_GM_ID`,
  `wl_dic_xl`.`XL_ID` AS `XL_ID1`,
  `wl_tbl_sp`.`TYSP_ID`,
  `wl_dic_tyjj_bz`.`TYSP_ID` AS `TYSP_ID1`,
  `wl_dic_tyjj_bz`.`TYSP_Y_PRICE_BC2`,
  `wl_dic_tyjj_bz`.`TYSP_Y_PRICE_BC`,
  `wl_dic_tyjj_bz`.`TYSP_Y_PRICE_MDM`,
  `wl_dic_tyjj_bz`.`TYSP_Y_PRICE_MDW`,
  `wl_dic_tyjj_bz`.`TYSP_N_PRICE`,
  `wl_dic_xl`.`XL_LC`,
  `wl_tbl_sp`.`TYSP_BZ_VWR`,
  `wl_tbl_sp`.`TYSP_GG`,
  `wl_tbl_sp`.`HW_JLDW`
FROM
  `wl_dic_xl`
  INNER JOIN `wl_dic_tyjj_bz` ON (`wl_dic_xl`.`XL_ID` = `wl_dic_tyjj_bz`.`XL_ID`)
  INNER JOIN `wl_tbl_sp` ON (`wl_dic_tyjj_bz`.`TYSP_ID` = `wl_tbl_sp`.`TYSP_ID`)
        WHERE 
                `wl_dic_tyjj_bz`.`XL_ID`=$xlid 
        and 
                `wl_dic_tyjj_bz`.`TYSP_ID`=$sp_id 
        and `wl_dic_tyjj_bz`.`W_FIELD_1` <=$zl 
        and `wl_dic_tyjj_bz`.`W_FIELD_2` >=$zl"; 
// echo $sql;

解决方案 »

  1.   

    。。
    do {
        if ($res = $page->query($sql, 1)==true) {
            $data = $page->getData() ;
     @extract ($data[1]); 
    // 输出一般客户价格页面
    include_once("../html/price_ybkh.html");
            break;
        }
    //elseif{
    // $data = $page->getData() ;
    //include_once("../html/price_ybkh_norecord.html")
    //print_r"$sql";
    //}    if ($res2 = $page->query($sql2, 1)==true) {
         $data = $page->getData() ;
    //  @extract ($data[1]); 
    // 输出等级客户价格页面
    include_once("../html/price_djkh.html");    
            break;
        }  
          if ($res3 = $page->query($sql3, 1)==true) {
         $data = $page->getData() ;
    //  @extract ($data[1]); 
    // 输出特殊客户部分
    include_once("../html/price_tzkh.html");    
            break;
        }
    } while(0);?>
      

  2.   

    我写的sql语句如下:
          for($i=0;$i<$rows;$i++)    //先查出该区下的所有段号
      {
      for($j=0;$j<$row_s;$j++)  //再查出所有的业务类型
      {
            $query="select count(ocontent) ocont_num,x.unitname,y.segmentno from tems t, tbusiness_unit x, tsegment y, tbusinessrear z where t.ocontent = x.unitname and  t.canumber=y.segmentno and t.id = z.businesssheetid and (z.businessrearcategoryid = 16 or z.businessrearcategoryid = 17) and y.areano = '".$SelectNumber."' and  (trunc(z.businessreartime) between to_date('$startdate','yyyy-mm-dd') and to_date('$enddate','yyyy-mm-dd')+1) and y.segmentno='".$results['SEGMENTNO'][$i]."' and x.unitname='".$result_s['UNITNAME'][$j]."' group by x.unitname,y.segmentno ";
                $stmt=ociparse($conn,$query); //echo $query;
            $ok2=ociexecute($stmt,oci_default);
            $row_all=ocifetchstatement($stmt,$result_all);
            ocifreestatement($stmt);
      }
      }
      

  3.   

    页面输出部分: 
     <table width='99%' border=1 cellpadding=0 cellspacing=0 bordercolorlight=black bordercolordark=white style='background-color:#FFFFFF;color:black;font-size:10pt'>
       <tr>
       <td>段号</td>
       <?
         for($j=0;$j<$row_s;$j++)
     {
     echo "<td>".$result_s['UNITNAME'][$j]."</td>";
     }
       ?>
       </tr>
       <?
         for($i=0;$i<$rows;$i++)
     {
       echo "<tr>";
           echo "<td>".$results['SEGMENTNO'][$i]."</td>";
        for($j=0;$j<$row_s;$j++)
            {
      echo "<td>".$result_all['OCONT_NUM'][$i][$j]."&nbsp;</td>";
        }
       echo "</tr>";
     }
       ?>
      </table>但发现用for循环嵌套速度很慢,因为对应于m行,n列的数据,就要查m*n次,然后再依次读出来显示,请问还有什么好办法能解决吗?急盼望。
      

  4.   

    用循环加嵌套查询试试:
    建两张表:
    CREATE TABLE TEMP_M ( 
      DUAN  NUMBER (6), 
      QU    NUMBER (6))CREATE TABLE TEMP_N ( 
      YE_NO    NUMBER (6), 
      YE_TYPE  CHAR (6), 
      YE_DUAN  NUMBER (6))
    //=====================================
         $ps_qu=$_POST['选择的区号']
         $conn=OCIPLogon("xxx", "xxx", "xxx");
         $strsql="select duan from temp_m where qu=$ps_qu";
         $re= OCIParse( $conn, $strsql );
         $excu=OCIExecute($re);
             echo "<TABLE border=1><TR>
          <TD>  段 </TD>
          <TD> 类型</TD>
          <TD> 统计</TD>
       </TR>";
         while(OCIFetchInto($re,$row)) {         $strsql="select max(ye_type),count(ye_type) from temp_n where ye_duan=$row[0] group by ye_type";         $re2= OCIParse( $conn, $strsql );
             $excu2=OCIExecute($re2);
             while(OCIFetchInto($re2,$row2)) {             echo "
       <TR>
          <TD>
             $row[0]
          </TD>
          <TD>
             $row2[0]
          </TD>
          <TD>
             $row2[1]
          </TD>
       </TR>";
             }
         }
         echo "</TABLE>";
      

  5.   

    你做了m*n次查询,当然是很慢了select COUNT(DISTINCT ...) from M,N where M.id=N.id and M.code=code group by M.id
      

  6.   

    to : xuzuning(唠叨) 
    如果不执行m*n次查询,如何能够实现呢?上面的表中的行和列都是从数据表中取出来的呀。要统计他们我想不出再好的方法了,请赐教!能介绍个更好的方法来实现吗?
      

  7.   

    to  nnnjjj(八仙过海) 
      你写的是实现  段号    类型   统计
                    D2      A      5
                    D2      B      8
                    ................
                    C1      A      10
    但我要的统计格式如下:
                    段 号\业务类型| 类型A   B   C   D  ......
                    段号x             10   5       3
                    段号y             3    8   5   4  即每一个段号可以统计出所有的类型。
      

  8.   

    CREATE TABLE M (       //段号表:M
      DUAN  NUMBER (6),    //段号
      QU    NUMBER (6))    //区号CREATE TABLE N (       //业务类型表N
      YE_NO    NUMBER (6), 
      YE_TYPE  CHAR (6), 
      YE_DUAN  NUMBER (6))create table tems     //业务表
      no     number(10),       id号
      duan   number(10),  //段号
      ye_type  char(6),   //业务类型
        
      

  9.   

    xuzuning(唠叨) 兄 在吗?