Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSON和PHP驱动的幻灯片放映不起作用_Php_Jquery_Json - Fatal编程技术网

JSON和PHP驱动的幻灯片放映不起作用

JSON和PHP驱动的幻灯片放映不起作用,php,jquery,json,Php,Jquery,Json,我从一个客户端继承了一个项目,该客户端使用JSON和PHP显示在线房地产服务的房地产清单。服务提供的数据会加载,但与之相关的属性和代理会混淆。有时会显示所有属性,但只有一个代理与它们关联。其他时候,数据会加载,但在显示一些属性后不会转换。转换由jQuery循环插件控制 我已经包括了下面的所有代码。非常感谢您的帮助 多谢各位 迈克 $date=time(); $dataType='4';//数据类型=代理 $companyID='2119';//马鹿-21世纪的优势 $url=$BASE\u

我从一个客户端继承了一个项目,该客户端使用JSON和PHP显示在线房地产服务的房地产清单。服务提供的数据会加载,但与之相关的属性和代理会混淆。有时会显示所有属性,但只有一个代理与它们关联。其他时候,数据会加载,但在显示一些属性后不会转换。转换由jQuery循环插件控制

我已经包括了下面的所有代码。非常感谢您的帮助

多谢各位

迈克

$date=time();
$dataType='4';//数据类型=代理
$companyID='2119';//马鹿-21世纪的优势
$url=$BASE\u url'/FeaturedDataHandler.c?r='$日期。”&数据类型='$数据类型。”&CompanyID='$公司ID;
//创建一个新的cURL资源
$ch=curl_init();
//设置URL和其他适当的选项
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_头,0);
//抓取URL并将其传递给浏览器
$response=curl\u exec($ch);
//关闭cURL资源,释放系统资源
卷曲关闭($ch);
$agents=decode_json_字符串($response);
foreach($代理作为$代理){
$properties=get_agent_properties($agent['WTLUserID']);
foreach($properties作为$property){
打印物业详情($property,$agent);
}
}

在调试这里的
decode\u json\u string()
函数之前,您应该先试用PHP内置的
json\u decode()


如果您有一个旧版本的PHP缺少
json\u decode()
,您可以在

中找到一个兼容的PHP,请先自己调试一下。
<?php
function decode_json_string($json){
    $objects = array();

    $start_pos = strpos($json, '[');
    $end_pos = strpos($json, ']');

    $dataString = substr($json, ++$start_pos, ($end_pos - $start_pos));

    while(strpos($dataString, '{') !== FALSE){
        $start_pos = strpos($dataString, '{');
        $end_pos = strpos($dataString, '}');

        $objectString = substr($dataString, ++$start_pos, ($end_pos - $start_pos));

        $tempString = $objectString;

        $formattedString = "";

        while(strpos($tempString, ':') !== FALSE){
            $valueStart = strpos($tempString, ':');

            if($tempString[++$valueStart] != '"'){

                $substring1 = substr($tempString, 0, $valueStart);

                if(strpos($tempString, ',', $valueStart) !== FALSE){
                    $valueEnd = strpos($tempString, ',', $valueStart);

                    $substring2 = substr($tempString, $valueStart, ($valueEnd - $valueStart));
                }
                else{
                    $valueEnd = $valueStart + 1;
                    $substring2 = substr($tempString, $valueStart);
                }

                $formattedString .= $substring1 . '"' . $substring2 . '"';

                $tempString = substr($tempString, $valueEnd);
            }
            else{
                $valueEnd = strpos($tempString, '",') + 1;

                $formattedString .= substr($tempString, 0, $valueEnd);
                $tempString = substr($tempString, $valueEnd);
            }
        }

        $tempArray = explode('",', $formattedString);

        foreach($tempArray as $tempValue){
            $tempValueArray = explode( ":", $tempValue);

            $key = format_string($tempValueArray[0]);
            $value = format_string($tempValueArray[1]);

            $object[$key] = $value;
        }

        $objects[] = $object;

        $dataString = substr($dataString, ++$end_pos);
    }

    return $objects;
}

function format_string($string){
    $string = str_replace("'", "", $string);
    $string = str_replace('"', "", $string);

    return trim($string);
}

function get_agent_properties_json($agentID){
    global $BASE_URL;

    $date = time();
    $dataType = '3'; // Data Type = Properties

    $url = $BASE_URL . '/FeaturedDataHandler.c?r=' . $date . '&DataType=' . $dataType . '&CompanyID=' . $companyID . '&agentID=' . $agentID;

    // create a new cURL resource
    $ch = curl_init();

    // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, 0);

    // grab URL and pass it to the browser
    $response = curl_exec($ch);

    // close cURL resource, and free up system resources
    curl_close($ch);

    return $response;
}

function get_agent_properties($agentID){
    $agent_properties_json = get_agent_properties_json($agentID);
    $properties = decode_json_string($agent_properties_json);

    return $properties;
}

function print_property_details(&$property, &$agent){
    global $BASE_URL;

    if($property['ListingStatusCode'] != 'SOLD'){
        $address = $property['Address'];
        $shortaddr = substr($address, 0, -12);
        echo "<div class='propertySlide'>";
            echo "<div class='title'>";
                echo "<div class='box1'>";
                    echo "<span class='price'>". $property['Price'] ."</span>";
                    echo "<span class='address'>". $shortaddr ."</span>";
                echo "</div>";
                echo "<div class='box2'>";
                    echo "<span class='style'><strong>Style:</strong> ". $property['Style'] ."</span>";
                    echo "<span class='footage'><strong>Sq. Feet:</strong> ". $property['SqFootage'] ."</span>";
                    echo "<span class='beds'><strong>Beds:</strong> ". $property['Bedrooms'] ."</span>";
                    echo "<span class='baths'><strong>Baths:</strong> ". $property['Bathrooms'] ."</span>";
                    echo "<span class='year'><strong>Year Built:</strong> ". $property['YearBuilt'] ."</span>";
                echo "</div>";
            echo "</div>";
            echo "<div class='imagebox'><img class='listingImage' src='". $BASE_URL . $property['Image'] ."' /></div>";
            echo "<div class='agentbox'>";
                echo "<img class='agentImage' src='" . $BASE_URL . "/Users/pic" .  $agent['WTLUserID'] . ".jpg' />";
                echo "<span class='agent'><strong>Agent:</strong> ". $agent['DisplayName'] ."</span>";
            echo "</div>";
        echo "</div>";
    }
}
$date = time();
$dataType = '4'; // Data Type = Agents
$companyID = '2119'; // Red Deer - Century 21 Advantage

$url = $BASE_URL . '/FeaturedDataHandler.c?r=' . $date . '&DataType=' . $dataType . '&CompanyID=' . $companyID;

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
$response = curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

$agents = decode_json_string($response);

foreach($agents as $agent){
    $properties = get_agent_properties($agent['WTLUserID']);

    foreach($properties as $property){
        print_property_details($property, $agent);
    }
}

<?php
$BASE_URL = 'http://www.century21.ca';

$date = time();
$dataType = '4'; // Data Type = Agents
$companyID = '2119'; // Red Deer - Century 21 Advantage

$url = $BASE_URL . '/FeaturedDataHandler.c?r=' . $date . '&DataType=' . $dataType . '&CompanyID=' . $companyID;

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
$response = curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

$agents = decode_json_string($response);

foreach($agents as $agent){
    $properties = get_agent_properties($agent['WTLUserID']);

    foreach($properties as $property){
        print_property_details($property, $agent);
    }
}