無法得到資料庫中的求和值,勞各位大神幫我看看!

來源:互聯網
上載者:User
$xmpc_id='4';/******************************************/$query1=mssql_query("select * from tb_xm where xm_pcid='$xmpc_id'");while($myrow1=mssql_fetch_assoc($query1)){$query12=mssql_query("select sum(xmpf_small_zf) as zf from tb_xmpf where xmpf_xm='$myrow2[xm_name]'");echo $myrow1[xm_name];echo $query12;echo "數量:";echo mssql_num_rows($query12);echo "總分值:";while($myrow12=mssql_fetch_array($query12)){ echo $myrow12[zf]; }


回複討論(解決方案)

列印出sql語句,放到phpmyadmin執行以下

是 echo $myrow12[zf]; 沒有輸出
還是都沒有輸出?

是 echo $myrow12[zf]; 沒有輸出,其他的輸出是有的。

直接把$query12的內容放在資料庫管理工具上執行是什麼結果

我重新改了一下程式,貌似while($myrow12=mssql_fetch_array($query12)下才能讀取資料庫的內容,我還想請教一下如何求解均值呢?

不是有 avg 函數嗎

謝謝,我找到了,可是所得到的值無法寫入資料庫?說$query3錯誤,這是為什麼啊?

$query1=mssql_query("select * from tb_xm where xm_pcid='$xmpc_id'");while($myrow1=mssql_fetch_assoc($query1)){echo $myrow1[xm_name];$query2=mssql_query("select sum(xmpf_small_zf) as zf from tb_xmpf where xmpf_xm='$myrow1[xm_name]'");//echo $query2;echo "總分:";while($myrow2=mssql_fetch_assoc($query2)){ echo $myrow2[zf]; $query3=mssql_query("update tb_xm set xm_zf='$myrow2[zf]' where xm_name='$myrow1[xm_name]'"); }   $query4=mssql_query("select avg(xmpf_small_zf) as avgf from tb_xmpf where xmpf_xm='$myrow1[xm_name]'"); //echo $query4; echo "平均分:"; while($myrow4=mssql_fetch_assoc($query4)){ echo $myrow4[avgf]; $query5=mssql_query("update tb_xm set xm_avg='$myrow4[avgf]' where xm_name='$myrow1[xm_name]'"); } 
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.