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 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架