2013-02-27 46 views
0

嗨所以我創建使用Foursquare的API在某一領域的趨勢地點清單從Foursquare的API趨勢列表:請參見以下鏈接http://createmate.co/foursquare-whatshot/如何將鏈接添加到什麼使用PHP

我試圖找出如何讓每個項目鏈接到其各自的Foursquare網址。這裏是到目前爲止的代碼...

<!doctype html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <title>Foursquare What's Hot</title> 

    <!-- external CSS link --> 
    <link rel="stylesheet" href="css/normalize.css"> 
    <link rel="stylesheet" href="css/style.css"> 
</head> 

<body> 
    <div id="container"> 

     <h1>Foursquare What's Hot</h1> 
     <?php 

      /* GET THE DATA */ 

      $trending_url = file_get_contents("https://api.foursquare.com/v2/venues/trending?ll=40.7,-74&oauth_token=BQEPEMYIFHHH2C1OGBTJDI4GBYV5HQAPNFLR5ON1JIAI42GN&v=20130220"); 

      $trending_output = json_decode($trending_url); 



      /* TEST THE DATA */ 

      //echo "<pre>"; 
      //print_r($trending_output); 
      //echo "</pre>"; 


      /* PRINT RESULTS */ 
      for ($i=0;$i<10;$i++) { 
       echo "<ul id ='locations'>"; 
       echo "<li> <a href= " . $trending_output->response->venues[$i]->canonicalURL . "> <h3>" . $trending_output->response->venues[$i]->name . "<br>"; 
       echo "<li> <h4>" . $trending_output->response->venues[$i]->location->address . "<br>"; 
       echo "</ul>"; 
      } 



     ?> 



    </div> 
</body> 

任何幫助深表感謝。

亞當

+0

你可以粘貼'print_r($ trending_output);'的輸出給我們嗎? – mkaatman 2013-02-27 19:37:12

回答

0

您檢索的屬性應該是canonicalUrl,不canonicalURL

您還應該將您的href屬性用引號括起來,並且別忘了關閉您的<a>標籤。

+0

現在我唯一遇到的就是這個奇怪的未定義偏移量:錯誤。任何想法爲什麼會發生? – 2013-05-28 21:33:13

+0

看起來像你的PHP有腥意,可能與你的索引有關(也許是一個OBOE?)http://stackoverflow.com/questions/9399509/getting-rid-of-php-notice-undefined-offset – octopi 2013-05-28 22:23:05