dty3416 2014-07-02 20:46
浏览 46
已采纳

Instagram照片数组所有照片到所选照片数组[关闭]

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}\";">
    }                                       
?>
  • 写回答

1条回答 默认 最新

  • doutan3192 2014-07-02 21:43
    关注

    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>"
    }                                       
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应