關於smarty取oracle資料數組後傳遞時,只取每個欄位第一個字元的有關問題

來源:互聯網
上載者:User
關於smarty取oracle資料數組後傳遞時,只取每個欄位第一個字元的問題
我剛接觸smarty,在擷取oracle資料以後,傳遞時發現只取每個欄位的第一個字元,而且還是亂碼。

代碼如下:
smarty.php



include 'ora/oraconn.php';

$dRootDir = '../../';

require_once($dRootDir . '_config.php');
require_once($dRootDir . 'inc/params.php');
require_once($dRootDir . 'inc/classes/db.php');
require_once($dRootDir . 'inc/classes/template.php');
require_once($dRootDir . 'inc/classes/util.php');

$tpl = new Template($gTemplate);
Util::gpc();


$sql="SELECT bpcnum_0 as BPCNUM,bpcnam_0 AS BPCNAM from bpcustomer where rownum<10";
$stmt = oci_parse($conn, $sql);

oci_execute($stmt);

$array = oci_fetch_array($stmt, OCI_BOTH);

$tpl->assign('ssss',$array);
$tpl->assign("News_CH", $array);
unset($array);
$tpl->display('smarty.tpl');
?>


以下是smarty.tpl








{--section name=customer loop=$News_CH--}
  • {--$News_CH[customer].BPCNAM--}

  • {--/section--}




    請高手不吝賜教,哪裡出了問題。謝謝!
    ------解決方案--------------------
    先不管 smarty
    在 $array = oci_fetch_array($stmt, OCI_BOTH);之後
    print_r($array);
    看看都是些什麼

    ------解決方案--------------------
    我要看到你從資料庫讀出的資料!

    按 oci_fetch_array($stmt, OCI_BOTH) 應該是下標數組
    那麼 $News_CH[customer].BPCNUM 就是錯的

    但需要看到資料才能確定
    ------解決方案--------------------
    在smarty.php 中 print_r($array);exit(); 看看是什麼結果。
    ------解決方案--------------------
    可能你輸出的不是一個正常的數組,看下輸出的資料有沒有問題;
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.