技术开发 频道

PHP开发之Foursquare API教程

  清单 3. 构建 index.php 视图

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    
<title>FourSquare API Test</title>
    
<link rel="stylesheet" type="text/css" href="css/960.css" media="all" />
    
<link rel="stylesheet" type="text/css" href="css/reset.css" media="all" />
    
<link rel="stylesheet" type="text/css" href="css/text.css" media="all" />
    
<link rel="stylesheet" type="text/css" href="css/tables.css" media="all" />


</head>
<body>
    
<div class="container_12">
        
<div class="grid_12">
        
<h1>FourSquare API Test</h1>
        
</div>
    
</div>


    
<div class="container_12">
        
<div class="grid_12" id="updates">
        
<?php
        include_once
'feed.php';
         $final = array();
        
         foreach ($venues_array
->groups[0]->venues as $v){
            
if (isset($v->phone)){
                 $PHONE
= $v->phone;
             }
else{
                 $PHONE
= "not listed";
             }
            
             $final[$v
->id] = array(
                            
'name' => $v->name,
                             'address' => $v->address,
                             'herenow' => $v->stats->herenow,
                             'phone' => $PHONE
                             );
        
         }
        
         ?
>
        
        
<table border='1' cellspacing='0' cellpadding='0'>
         <thead>
            
<tr valign='top'>
             <th>Location</th>
            
<th>Address</th>
            
<th>Phone</th>
            
<th>Here Now</th>
            
</tr>
        
</thead>
        
<tbody>
        
<?php
         foreach ($final
as $key => $data){
             echo
"<tr valign='top'>";
             echo
"<td>".$data['name']."</td>\n";
             echo "<td>". $data['address']."</td>\n";
             echo "<td>". $data['phone']."</td>\n";
             echo "<td align='center'>". $data['herenow']."</td>\n";
             echo "</tr>\n";
         }
         ?
>
        
</tbody>
        
</table>
        
        
</div>
    
</div>
</body>
</html>

  超出 PHP 之外的大部分代码示例都只是为了便于人们查看,不一定有用。您可以应用自己的样式和方法来让信息显得直观明了。例如,您可以将来自 PHP 文件的 JSON 提要绑定到 jQuery.getJSON() 方法中,以便无需刷新 Web 页面即可刷新它。

  您还可以使用一个更简单、直观的列表来展现信息,使其在一个小的智能手机屏幕的上下文内看起来更自然。例如,清单 4 显示最终的 foreach 循环,生成了一个列表。

0
相关文章