phantomlimb Posted October 2, 2009 Share Posted October 2, 2009 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)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/176260-targetting-multiple-variables-in-an-array-possible/ Share on other sites More sharing options...
RussellReal Posted October 2, 2009 Share Posted October 2, 2009 can't tell you since you're using your own class there Quote Link to comment https://forums.phpfreaks.com/topic/176260-targetting-multiple-variables-in-an-array-possible/#findComment-928921 Share on other sites More sharing options...
phantomlimb Posted October 2, 2009 Author Share Posted October 2, 2009 I'm actually working with Dan Coulter's excellent PHPFlickr class. But am trying to modify it to suit my needs with unfortunately limited PHP knowledge. Wanna tell me now Quote Link to comment https://forums.phpfreaks.com/topic/176260-targetting-multiple-variables-in-an-array-possible/#findComment-928939 Share on other sites More sharing options...
RussellReal Posted October 2, 2009 Share Posted October 2, 2009 I'd LOVE to help you but I just really can't without some more information, post the class here and I'll see what I can whip up . Quote Link to comment https://forums.phpfreaks.com/topic/176260-targetting-multiple-variables-in-an-array-possible/#findComment-929185 Share on other sites More sharing options...
mikesta707 Posted October 2, 2009 Share Posted October 2, 2009 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))); Quote Link to comment https://forums.phpfreaks.com/topic/176260-targetting-multiple-variables-in-an-array-possible/#findComment-929189 Share on other sites More sharing options...
lipun4u Posted October 3, 2009 Share Posted October 3, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/176260-targetting-multiple-variables-in-an-array-possible/#findComment-929381 Share on other sites More sharing options...
phantomlimb Posted October 4, 2009 Author Share Posted October 4, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/176260-targetting-multiple-variables-in-an-array-possible/#findComment-929988 Share on other sites More sharing options...
mikesta707 Posted October 4, 2009 Share Posted October 4, 2009 i've never heard of in_all_arr in my life, so unless you provide the definition for that function, it won't work. I did a google search for it to no avail. try this $photos = $f->photos_search(array("tags"=>".$pod.",".$loc.",".$act, "tag_mode"=>"any")); Quote Link to comment https://forums.phpfreaks.com/topic/176260-targetting-multiple-variables-in-an-array-possible/#findComment-929999 Share on other sites More sharing options...
phantomlimb Posted October 6, 2009 Author Share Posted October 6, 2009 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")); Quote Link to comment https://forums.phpfreaks.com/topic/176260-targetting-multiple-variables-in-an-array-possible/#findComment-931356 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.