2016-12-14 62 views
-2

我希望我就在这里。Json PHP输出数字(整数)

我从一个JSON文件制作一个搜索引擎,把我的数据(URL) 我可以读出我的代码文本(PHP)

<?php 
 

 
foreach ($obj['Products'] as $key => $value) { 
 
echo '<p>Artikel: '.$value['ProductName']. '</p> <br/>'; 
 
echo '<p> Produktbeschreibung: '.$value['Description'].'</p> <br/><br/>'; 
 

 
echo '<a href="' .$value['Deeplink1'].'" target="_blank"> zum Shop </a><br/><br/>'; 
 

 
} 
 

 

 
$service = "http://dateck-media.de/sf/ddd.php ;This is the JSON // Put together request $request = $service . "?" . http_build_query($params); Get response $response = file_get_contents($request,TRUE); $obj = json_decode($response,true);

但现在我想显示我的搜索结果。在我的JSON文件,它看起来像

Array ( 
    [ProductsSummary] => Array ( 
     [Records] => 20 
     [TotalRecords] => 41 
     [TotalPages] => 3 
     [CurrentPage] => 1 
    ) 
    [Products] 

我不知道如何让[Totalrecords]在我的代码来呼应"You have [TotalRecords] for your search"

请帮助我。

+0

搜索结果的数量,我的意思是!我需要在我的html文件中使用TotalRecords => 41

+0

如果您的JSON文件看起来像这样,它不是JSON。此外,您提供的代码似乎与您的问题无关。那个代码有问题吗?你能提供你的JSON文件的确切内容,以及如何转换它? – trincot

+0

$ service =“https://product-api.affili.net/V3/productservice.svc/JSON/SearchProducts”;这是JSON //放在一起请求 $ request = $ service。 “?” 。 http_build_query($ params)方法;获取回复 $ response = file_get_contents($ request,TRUE); $ obj = json_decode($ response,true); –

回答

0

可以按如下步骤(你有循环外)的总写:

echo "You have {$obj['ProductsSummary']['TotalRecords']} results for your search"; 
+0

oh thx trincot !!!而已 !我看到...我忘记了{通过{$ obj ['ProductsSummary'] ....谢谢youuuu –

0

THX所有和我的英语很抱歉...现在我会尽量把Total-和CurrentPages在搜索结束后,前进到下一个网站!但首先我要单独尝试:-)