Jump to content

Targetting multiple variables in an array? Possible?


phantomlimb

Recommended Posts

Hi,

 

Doing some work with PHP and flickr. Hoping to get some help on this piece of PHP i've been working on, below is the particular snippet i'm tring to figure out. I have three varaibles being passed via URL $pod, $loc, and $act.

 

Secondly i have a search array. At the moment i have the array fetching tags that match the variable $pod. What i want to know is, is there any possible way of fetching tags that match all three variables $pod, $loc and $act?  Any help appreciated.

 

<?php
$pod = $_GET['pod'];
$loc = $_GET['loc'];
$act = $_GET['act'];
$photos = $f->photos_search(array("user_id"=>$person['id'], "tags"=>$pod));
?>

Link to comment
Share on other sites

it seems that you would probably have to change the function (Or create a different one) that will accept an array of tags rather than just 1 tag. Have you tried just putting an array of the tags where the 1 tag is? if that doesn't work than you will have to change the function/make a new one

 

IE

$pod = $_GET['pod'];
$loc = $_GET['loc'];
$act = $_GET['act'];
$photos = $f->photos_search(array("user_id"=>$person['id'], "tags"=>array($pod, $loc, $act)));

Link to comment
Share on other sites

As u or somebody else has defined the class, we don't know how that function deals with these things. So consider the following code...

<?php
$pod = $_GET['pod'];
	$loc = $_GET['loc'];
	$act = $_GET['act'];
	$ph1 = $f->photos_search(array("user_id"=>$person['id'], "tags"=>$pod));
$ph2 = $f->photos_search(array("user_id"=>$person['id'], "tags"=>$loc));
    $ph3 = $f->photos_search(array("user_id"=>$person['id'], "tags"=>$act));
$photos = in_all_arr($ph1, $ph2, $ph3);
?>

 

ph1, ph2 and ph3 will contain the photos matching the individual tags.

in_all_arr() wil return the photos which are in all three arrays.

 

N.B. This method is a performance overhead.

Link to comment
Share on other sites

Thanks heaps for all of your suggestions, i have tried both the solutions proposed with no luck. Here is the particular PHPFlickr function i am working with, it interacts with the Flickr API.

 

function photos_search ($args = array()) {
	/* This function strays from the method of arguments that I've
	 * used in the other functions for the fact that there are just
	 * so many arguments to this API method. What you'll need to do
	 * is pass an associative array to the function containing the
	 * arguments you want to pass to the API.  For example:
	 *   $photos = $f->photos_search(array("tags"=>"brown,cow", "tag_mode"=>"any"));
	 * This will return photos tagged with either "brown" or "cow"
	 * or both. See the API documentation (link below) for a full
	 * list of arguments.
	 */

	/* http://www.flickr.com/services/api/flickr.photos.search.html */
	$this->request("flickr.photos.search", $args);
	return $this->parsed_response ? $this->parsed_response['photos'] : false;
}

 

Code to retrieve photos based on mikesta's proposal:

<?php
require_once("phpFlickr/phpFlickr.php");
$f = new phpFlickr("XXXXXXXX");
$person = $f->people_findByUsername("XXXXXXXX");
$pod = $_GET['pod'];
$loc = $_GET['loc'];
$act = $_GET['act'];
$i = 0; // Counter variable
$photos = $f->photos_search(array("user_id"=>$person['id'], "tags"=>array($pod, $loc, $act), "tag_mode"=>"any"));
?>

 

Code to Display Photos

 

<? foreach ((array)$photos['photo'] as $id=>$phototagged) : ?>
<div><a href="<?= $f->buildPhotoURL($phototagged, 'medium') ?>"> <img border='0' alt="<? $phototagged[title] ?>" src="<?= $f->buildPhotoURL($phototagged, 'square') ?>" class="opacity"/> </a> </div> <? $i++; ?>
<?php endforeach; ?>

 

With this particular code it is displaying all the photos rather than the photos based on the $pod, $act, or $loc variables i pass through the URL. With Lipun4u's suggestion i get a Call to undefined function in_all_arr() error.

Link to comment
Share on other sites

Thanks for the effort Mikesta. Still no luck though.

 

I get a syntax error, unexpected T_STRING, expecting ')'

 

I tried changing the code to the following which didn't return any errors but the only variable that was recognised was the first one $pod.

 

$photos = $f->photos_search(array("tags"=>".$pod.",".$loc.",".$act.", "tag_mode"=>"any"));

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.