Instagram的照片阵列的所有照片中选定的照片阵列 [英] Instagram Photos array with all photos to array of selected photos
问题描述
我试图建立我的Instagram的API的网站,使用户可以选择照片
我能够将数据保存在数据库中,并显示照片,但不能使照片可选择在不同的阵列
下面是我的code:
< PHP
在session_start();
需要'db.php中;
需要'instagram.class.php';
需要'instagram.config.php'; 如果(!空($ _ SESSION ['的UserDetails']))
{
$数据= $ _ SESSION ['的UserDetails']; //存储用户的访问令牌
$ instagram-> setAccessToken($的数据); }
其他
{
标题(位置:的index.php');
} ?>
< PHP $流行= $ instagram-> getUserMedia($数据 - >用户可和SEQ ID); //显示结果
的foreach($ popular->的数据作为$的数据)
{
回声< IMG SRC = \\{$数据 - >图像 - > thumbnail-> URL} \\;>
}
?>
您不能使图像选择使用PHP,你需要做的一些JavaScript和CSS样式
img.selected {
边框:1px的固体绿色;
}
然后用一些JavaScript,你可以找到所有与 document.images
或 document.getElementsByTagName('IMG')$ C图像$ C>。这将是最好的,如果你给了他们所有的一类从
document.getElementsByClassName选择('斯塔-照片')
,其中图像类
属性是斯塔-照片
...一旦你有图像列表,你可以添加一些事件处理的选择,所有你需要做的是取消选择所有其它图像(即删除选
从所有图像类),并通过更新其CSS类选择在当前以选择了
最后,使用PHP,你可以把该做从客户端和服务器的往返,显示选择图像中的每个图像周围的链接。你可以把它作为一个URL参数。
$选择=参数['选择'];//显示结果
的foreach($ popular->的数据作为$的数据)
{
$ CSS =斯塔-照片
如果($选择== $的数据){$ CSS =斯塔,照片入选}
回声< A HREF = \\{$数据 - >图像 - > thumbnail-> URL} \\类= \\{$}的css \\>中
回声< IMG SRC = \\{$数据 - >图像 - > thumbnail-> URL} \\>中
回声< \\ A>中
}
I'm trying to set up my Instagram API site so that users can select photos
I am able to save the data in an database and Display the photos but not able to make photos selectable in an different array
Here's my code:
<?php
session_start();
require 'db.php';
require 'instagram.class.php';
require 'instagram.config.php';
if (!empty($_SESSION['userdetails']))
{
$data=$_SESSION['userdetails'];
// Store user access token
$instagram->setAccessToken($data);
}
else
{
header('Location: index.php');
}
?>
<?php
$popular = $instagram->getUserMedia($data->user->id);
// Display results
foreach ($popular->data as $data)
{
echo "<img src=\"{$data->images->thumbnail->url}\";">
}
?>
you cannot make the images "selectable" with php, you need to do that with some javascript and css styles
img.selected {
border:solid 1px green;
}
Then with some javascript, you can find all the images with document.images
or document.getElementsByTagName('img')
. It would be best if you gave them all a class to select from document.getElementsByClassName('insta-photos')
where the images class
attribute is insta-photos
...once you have the list of images, you can add some event handling for the "selection", all you have to do is unselect all the other images (ie remove the selected
class from all of the images) and select the current one by updating its css class to "selected"
Ultimately with php, you could put a link around each image that did roundtrips from the client and the server, displaying the "selected" image. you can pass it in as a url parameter..
$selected = params['selected'];
// Display results
foreach ($popular->data as $data)
{
$css = "insta-photo"
if ($selected == $data) { $css = "insta-photo selected" }
echo "<a href=\"{$data->images->thumbnail->url}\" class=\"{$css}\">"
echo " <img src=\"{$data->images->thumbnail->url}\">"
echo "<\a>"
}
这篇关于Instagram的照片阵列的所有照片中选定的照片阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!