drz5553 2014-12-11 08:54
浏览 68

用php拉数据和循环

I have a php file that is trying to get information from a XML API using SOAP.

The code for pulling data is

 <?php
  // create SOAP client object
  $client = new SoapClient("http://www.bookingassist.ro/test/book.wsdl", array('trace' => 1));

  try {
      $rooms = array(); 
      // First Room
      $rooms[] = array(array("paxType" => "Adult"));
      $filters[] = array("filterType" => "resultLimit", "filterValue" => "6");     
      // (start search)
      $checkAvailability = $client->getAvailableHotel("APIKEY", "RHMK", "2015-04-20", "2015-04-27", "EUR", "RO", "false", $rooms, $filters);
  }
  catch (SoapFault $exception) {
      echo $exception->getMessage();
      exit;
  }

?>
 <?php
  if (is_object($checkAvailability->availableHotels)) 
  $hotelResponse[] = $checkAvailability->availableHotels;
  $hotelResponse = $checkAvailability->availableHotels;
  foreach ((array)$hotelResponse as $hnum => $hotel)
?>  

below in page i have the folowing code

<article class="box">
<h4><?php echo  $hotel->hotelCode?></h4>                                      
<span class="price">aprox/NOAPTE</small>€ <?php echo $hotel->totalPrice ?></span>
</article>

My query is can i loop the entire content from as many responses i have in the filters array ($filters[] = array("filterType" => "resultLimit", "filterValue" => "6"); )

I have tried the same but in a blank page withour any css onky a table with header abd uts extracting and looping the information as requested. - http://www.bookingassist.ro/test/test.php

  • 写回答

1条回答 默认 最新

  • doudizhu2222 2014-12-11 09:31
    关注

    If you are only getting one result I don't think the values you have in "$hotelResponse" are what you think.

    There's a good chance that your code is entering the second part of your if/else statement explaining why you are only getting one result.

    Do a var_dump on this to verify you have X amount of hotels

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看