Heim >Backend-Entwicklung >PHP-Tutorial >关于smarty取oracle数据数组后传递时,只取每个字段第一个字符的有关问题

关于smarty取oracle数据数组后传递时,只取每个字段第一个字符的有关问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:02:021039Durchsuche

关于smarty取oracle数据数组后传递时,只取每个字段第一个字符的问题
我刚接触smarty,在获取oracle数据以后,传递时发现只取每个字段的第一个字符,而且还是乱码。

代码如下:
smarty.php

<br /><?php<br /><br />include 'ora/oraconn.php';<br /><br />   $dRootDir = '../../';<br />   <br />   require_once($dRootDir . '_config.php');<br />   require_once($dRootDir . 'inc/params.php'); <br />   require_once($dRootDir . 'inc/classes/db.php');<br />   require_once($dRootDir . 'inc/classes/template.php');<br />   require_once($dRootDir . 'inc/classes/util.php');<br />      <br />$tpl = new Template($gTemplate);<br />Util::gpc();<br /><br /><br />$sql="SELECT bpcnum_0 as BPCNUM,bpcnam_0 AS BPCNAM from bpcustomer where rownum<10";<br />$stmt = oci_parse($conn, $sql);<br /><br />oci_execute($stmt);<br /><br />$array = oci_fetch_array($stmt, OCI_BOTH);<br /><br />$tpl->assign('ssss',$array);<br />	$tpl->assign("News_CH", $array);<br />	unset($array);<br />	$tpl->display('smarty.tpl');<br />?><br />


以下是smarty.tpl

<br /><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#B9E9FF"><br /><tr> <br /><td height="115" width="10"></td><br /><td valign="top" width="295" bgcolor="#B9E9FF"><br />{--section name=customer loop=$News_CH--}<br /><li ><a href="news.php?type=1&id={--$News_CH[customer].BPCNUM--}" >{--$News_CH[customer].BPCNAM--}<br /></a></li><br />{--/section--}<br /><br /></td><br /></tr><br /></table><br />


请高手不吝赐教,哪里出了问题。谢谢!
------解决方案--------------------
先不管 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(); 看看是什么结果。
------解决方案--------------------
可能你输出的不是一个正常的数组,看下输出的数据有没有问题;

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn