Php wo可以相互关联,即每个唯一的用户可以有许多观察列表,每个都有自己的唯一ID。谢谢,我明白你的意思。哪里是最好的地方,回声出这些变量,以获得信息,我需要为每一部电影。您是否可以提供一个示例?在中编辑了更多详细信息,主要是您需要存储数据,直到所有处理完成(最
Php wo可以相互关联,即每个唯一的用户可以有许多观察列表,每个都有自己的唯一ID。谢谢,我明白你的意思。哪里是最好的地方,回声出这些变量,以获得信息,我需要为每一部电影。您是否可以提供一个示例?在中编辑了更多详细信息,主要是您需要存储数据,直到所有处理完成(最,php,arrays,database,foreach,rotten-tomatoes,Php,Arrays,Database,Foreach,Rotten Tomatoes,wo可以相互关联,即每个唯一的用户可以有许多观察列表,每个都有自己的唯一ID。谢谢,我明白你的意思。哪里是最好的地方,回声出这些变量,以获得信息,我需要为每一部电影。您是否可以提供一个示例?在中编辑了更多详细信息,主要是您需要存储数据,直到所有处理完成(最好在“主”-数组中的相应项处)。如果你在论坛结束后发表一篇文章,你就会明白我的意思。非常好,非常感谢你的帮助。我只是想实现上面的建议,但是代码似乎在获得$rt_id和$films['watchlist_films']=$watchlist_fi
wo可以相互关联,即每个唯一的用户可以有许多观察列表,每个都有自己的唯一ID。谢谢,我明白你的意思。哪里是最好的地方,回声出这些变量,以获得信息,我需要为每一部电影。您是否可以提供一个示例?在中编辑了更多详细信息,主要是您需要存储数据,直到所有处理完成(最好在“主”-数组中的相应项处)。如果你在论坛结束后发表一篇文章,你就会明白我的意思。非常好,非常感谢你的帮助。我只是想实现上面的建议,但是代码似乎在获得$rt_id和$films['watchlist_films']=$watchlist_films之间失败。正如预期的那样,回显$rt\U id会获得每个观察列表中第一部电影的电影id,但回显$films['Watchlist\U films']只会给我一个空数组?我用不需要的部分缩短了代码,并删除了Rotter Tomatoe调用(由
///Rotter Tomato call/////code>行指示)只是为了节省答案中的空间。因此,您需要将调用放入,就像在初始代码中一样。
// Get a user's Watchlists from the watchlists table
$query = "SELECT * FROM watchlists WHERE user_id = " . $profile_info['id'];
$watchlist_result = mysql_query($query);
$watchlists = array();
while(($row = mysql_fetch_assoc($watchlist_result))) {
$watchlists[] = $row;
}
// Count how many Watchlists a user has
$watchlist_count = count($watchlists);
// Echo details of each Watchlist
echo "<pre>";
print_r($watchlists);
echo "</pre>";
// For each Watchlist, select all of the films it contains and echo them out
foreach ($watchlists as $key => $films) {
// Get each Watchlist's ID from the watchlists table
$watchlist_id = $films['watchlist_id'];
echo "<pre>";
print_r($watchlist_id);
echo "</pre>";
// Extract films from the watchlist_films table for each Watchlist, based on its unique ID and put them into an array
$watchlist_film_query = "SELECT * FROM watchlist_films WHERE watchlist_id = " . $watchlist_id;
$watchlist_film_result = mysql_query($watchlist_film_query);
$watchlist_films = array();
while(($row = mysql_fetch_assoc($watchlist_film_result))) {
$watchlist_films[] = $row;
}
// Echo the new array
echo "<pre>";
print_r($watchlist_films);
echo "</pre>";
// Get the ID of the first film in each Watchlist
$rt_id = $watchlist_films[0]['film_id'];
// Echo the ID
echo "<pre>";
print_r($rt_id);
echo "</pre>";
// Initialise Rotten Tomates API
include_once('/api/RottenTomatoes.php');
/* Rotten Tomatoes */
$rottenTomatoes = new RottenTomatoes('2b2cqfxyazbbmj55bq4uhebs', 10, 'uk');
// Search Rotten Tomatoes for details on the first film in the array
$rottenTomatoes->movieSearch($rt_id);
//echo "<pre>";
try {
$result = $rottenTomatoes->getMovieInfo($rt_id);
//print_r($result);
} catch (Exception $e) {
//print_r($e);
}
//echo "</pre>";
// Get poster and name of first movie in array
$thumbnail = $result['posters']['thumbnail'];
$first_film_name = $result['title'];
echo "<pre>";
print_r($thumbnail);
echo "</pre>";
echo "<pre>";
print_r($first_film_name);
echo "</pre>";
}
if ($watchlist_count != 0) {?>
<ul class="unstyled"><?php
foreach($watchlists as $key => $watchlist_item) {?>
<li class="well list-item clearfix"><?php
echo "<pre>";
print_r($watchlist_item);
echo "</pre>";
echo "<pre>";
print_r($watchlist_films);
echo "</pre>";
echo "<pre>";
print_r($watchlist_id);
echo "</pre>";
echo "<pre>";
print_r($thumbnail);
echo "</pre>";
echo "<pre>";
print_r($first_film_name);
echo "</pre>";?>
<div class="row-fluid">
<a href="watchlist.php?id=<?php echo $watchlist_item['watchlist_id']; ?>" title="<?php echo $watchlist_item['name']; ?> Watchlist">
<img src="<?php echo $thumbnail; ?>" class="span1 pull-left" alt="<?php echo $first_film_name; ?> poster" title="<?php echo $first_film_name; ?> poster" />
</a>
<div class="span11 movie-info">
<p class="search-title"><a href="watchlist.php?id=<?php echo $watchlist_item['watchlist_id']; ?>" title="<?php echo $watchlist_item['name']; ?> Watchlist"><?php echo $watchlist_item['name']; ?></a></p>
<p class="search-synopsis"><?php echo $watchlist_item['description']; ?></p>
</div>
</div>
</li><?php
}?>
</ul><?php
} else {?>
<div class="well list-item">
You haven't created any Watchlists yet! Why not visit a movie page now and build your first?
</div><?php
}?>
$films['watchlist_films']=$watchlist_films;
$films['thumbnail']=$thumbnail;
$films['first_film_name']=$first_film_name;
$watchlist_item['thumbnail'];
$watchlist_item['first_film_name'];
$query = "SELECT * FROM watchlists WHERE user_id = " . $profile_info['id'];
$watchlist_result = mysql_query($query);
$watchlists = array();
while(($row = mysql_fetch_assoc($watchlist_result))) {
$watchlists[] = $row;
}
// For each Watchlist, select all of the films it contains and echo them out
foreach ($watchlists as $key => $films) {
$watchlist_film_query = "SELECT * FROM watchlist_films WHERE watchlist_id = " . $films['watchlist_id'];
$watchlist_film_result = mysql_query($watchlist_film_query);
$watchlist_films = array();
//You don't need to load all data if you only want the first one:)
$row = mysql_fetch_assoc($watchlist_film_result)
$rt_id = $row['film_id'];
// Initialise Rotten Tomates API
include_once('/api/RottenTomatoes.php');
/////Rotten Tomato Call /////
//===> Rotten Tomatoe API call code goes here <=== //
//You don't really need the whole films list
//$films['watchlist_films']=$watchlist_films;
$films['thumbnail']=$result['posters']['thumbnail'];
$films['first_film_name']=$result['title'];
}
if (count($watchlists)> 0) {?>
<ul class="unstyled"><?php
foreach($watchlists as $key => $watchlist_item) {?>
<li class="well list-item clearfix"><?php
<div class="row-fluid">
<a href="watchlist.php?id=<?php echo $watchlist_item['watchlist_id']; ?>" title="<?php echo $watchlist_item['name']; ?> Watchlist">
<img src="<?php echo $watchlist_item['thumbnail']; ?>" class="span1 pull-left" alt="<?php echo $first_film_name; ?> poster" title="<?php echo $watchlist_item['first_film_name']; ?> poster" />
</a>
<div class="span11 movie-info">
<p class="search-title"><a href="watchlist.php?id=<?php echo $watchlist_item['watchlist_id']; ?>" title="<?php echo $watchlist_item['name']; ?> Watchlist"><?php echo $watchlist_item['name']; ?></a></p>
<p class="search-synopsis"><?php echo $watchlist_item['description']; ?></p>
</div>
</div>
</li><?php
}?>
</ul><?php
} else {?>
<div class="well list-item">
You haven't created any Watchlists yet! Why not visit a movie page now and build your first?
</div><?php
}?>