如何显示JSON结果中的所有子记录,而不仅仅是最后一条记录

时间:2013-05-28 15:52:35

标签: php javascript json dojo

目前我有多对一的关系,我需要我的地图查看器才能显示所有子记录,而不仅仅是最后一条记录。我已经研究过并发现可能我可能会再次重写变量,这就是为什么最后一条记录是唯一显示的记录。我做了测试以确保所有记录实际上都是通过使用fiddler来实现的。请帮忙。

请参阅下面的PHP代码

 <?php error_reporting(E_ERROR | E_WARNING | E_PARSE);
 $pole = $_GET["pole"];


 // Connect to SQL Server database
 include("../connections/PubgisConnect.php");

// Construct query
$tsql = "Select [dbo].[TRANS_POLE].[PoleID], [dbo].[TRANS_POLE].[PoleType], [dbo]. 
FROM [pubgis].[dbo].[TRANS_POLE]
INNER JOIN [pubgis].[dbo].[TRANS_SIGN] ON [pubgis].[dbo].[TRANS_POLE].[PoleID][pubgis]     [dbo].[TRANS_SIGN].PoleID INNER JOIN [pubgis].[dbo].[TRANS_SIGNINSPECTION] ON [pubgis].[dbo].[TRANS_SIGN].SignID = [pubgis].[dbo].[TRANS_SIGNINSPECTION].SignID
WHERE [pubgis].[dbo].[TRANS_POLE].[PoleID] = '$pole'";


// Execute query
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
  {
    echo "Error in executing query.</br>";
    die( print_r( sqlsrv_errors(), true));
  }
$results = array();
// Retrieve and display the results of the query 
$lastFeatType = "";
while($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC)) {
    array_push($results,$row);
  }

  echo json_encode($results);

 // Free statement and connection resources
 sqlsrv_free_stmt( $stmt);
 sqlsrv_close( $conn);
 ?> 

以下代码来自我的索引文件

dojo.xhrGet({
        url: "StreetSignsProfile.php",
        handleAs: "json",
        content:{pole: pole},
        load: function(data) {
            for (var i=0;i<data.length;i++) {
                var obj = data[i];
                var pole = obj["PoleID"];
                var encodedPole = encodeURIComponent(pole);
        var na = "<span class='notAvail'>not available</span >";
                dojo.byId("idHeader").innerHTML = obj["PoleID"];
                dojo.byId("PoleType").innerHTML = obj["PoleType"];

                //Sign Code
                dojo.byId("SignID").innerHTML = obj["SignID"];
                dojo.byId("SignCode").innerHTML = obj["SignCode"];.

查看以上结果                                                                                                                         极点信息                                                  极类型                                                                      

0 个答案:

没有答案