liamloveslearning Posted April 18, 2009 Share Posted April 18, 2009 Hey guys, I was wondering if someone could give me a hand and point me in the right direction. I'm basically working on a music mashup website, but have hit a brick wall at this moment in time. Here's the scenario: Basically all my data is coming from external API's and feeds, but for this particular section, I want to filter some of the data out in PHP. Here's a link to an example, just to make it easier to explain: http://cahamilton.at-uclan.com/fyp/query.php?artist=muse - At the top, you can see the list under the search bar (of other search results), which indicate the other bands "Names" and "MBID's". http://ws.audioscrobbler.com/2.0/?api_key=c7d55f27a911c6a0f77040f18758fc5a&method=artist.search&artist=muse - Here you can see the raw feed data from that search. Basically, what I want to do, is filter through the search data and present only the bands that have "MBID's" in there. Its just a way of filtering out inaccurate data from the site. If any of you are familiar with how Last.FM works, I imagine you know what I mean. Here is the current snippet of code I am working with: <?php // iterate over entries in feed foreach ($lastFM_searchXML->results->artistmatches->artist as $search_alternative) { // setup variables $alternative_mbid = $search_alternative->mbid; $alternative_name = $search_alternative->name; $alternative_picture = $search_alternative->image[2]; $alternative_picture2 = str_replace("serve/126","serve/34s",$alternative_picture); $alternative_url = 'query.php?artist='.urlencode($alternative_name); ?> <?php echo " <ul> <li>$alternative_name</li> <li>$alternative_mbid</li> </ul> <br />" ;?> <?php } ?> I've tried a bunch of functions such as "array_filter" and god knows what else. I just cant seem to get it working. I kind of new to PHP, so I'm still learning lol. Does anyone have any suggestions? Any help would be much appreciated! Cheers guys! Link to comment https://forums.phpfreaks.com/topic/154693-php-filtering/ Share on other sites More sharing options...
liamloveslearning Posted April 19, 2009 Author Share Posted April 19, 2009 bump Link to comment https://forums.phpfreaks.com/topic/154693-php-filtering/#findComment-813689 Share on other sites More sharing options...
Pawn Posted April 19, 2009 Share Posted April 19, 2009 Am I being a dunce? Won't this work? <?php if(!empty($alternative_mbid)) { echo "<ul> <li>$alternative_name</li> <li>$alternative_mbid</li> </ul> <br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/154693-php-filtering/#findComment-813691 Share on other sites More sharing options...
liamloveslearning Posted April 19, 2009 Author Share Posted April 19, 2009 No its doesn't unfortunately . Although, it could be on the lines of something.. Link to comment https://forums.phpfreaks.com/topic/154693-php-filtering/#findComment-813701 Share on other sites More sharing options...
liamloveslearning Posted April 19, 2009 Author Share Posted April 19, 2009 I'm just wondering, is that previous statement checking whether the $alternative_mbid is there, then echo'ing it whether its there or not?? Would we need something that says, if its not there, don't echo out the entry (which is the $search_alternative) and if it is, echo the whole entry out? I could be wrong, I'm still working my way round with PHP lol Link to comment https://forums.phpfreaks.com/topic/154693-php-filtering/#findComment-813702 Share on other sites More sharing options...
Pawn Posted April 19, 2009 Share Posted April 19, 2009 The statement is saying "if the variable $alternative_mbid is not empty, do the following". <?php // iterate over entries in feed foreach ($lastFM_searchXML->results->artistmatches->artist as $search_alternative) { // setup variables $alternative_mbid = $search_alternative->mbid; $alternative_name = $search_alternative->name; $alternative_picture = $search_alternative->image[2]; $alternative_picture2 = str_replace("serve/126","serve/34s",$alternative_picture); $alternative_url = 'query.php?artist='.urlencode($alternative_name); // check for mbid if(!empty($alternative_mbid)) { // mbid echo "<ul> <li>$alternative_name</li> <li>$alternative_mbid</li> </ul> <br />"; } else { // no mbid echo "This entry was omitted because it had no MBID."; } } ?> What happens when you run that? Link to comment https://forums.phpfreaks.com/topic/154693-php-filtering/#findComment-813707 Share on other sites More sharing options...
liamloveslearning Posted April 19, 2009 Author Share Posted April 19, 2009 No luck . Silly question, but is the code treating the Name and MBID as part of a single record? So when we figure out how to filter out the records, its getting rid of the whole record (name and mbid), if no MBID is found? Link to comment https://forums.phpfreaks.com/topic/154693-php-filtering/#findComment-813713 Share on other sites More sharing options...
Pawn Posted April 19, 2009 Share Posted April 19, 2009 Yes, it should suppress the display of the whole entry. I don't know why it doesn't. Link to comment https://forums.phpfreaks.com/topic/154693-php-filtering/#findComment-813720 Share on other sites More sharing options...
liamloveslearning Posted April 19, 2009 Author Share Posted April 19, 2009 Just a stab in the dark, would something like this work: http://uk.php.net/manual/en/function.array-filter.php ??? I tried doing something with it earlier yesterday, but didn't really know what I was doing. Seems slightly hopeful reading through it though. What do you think? Would it be possible with this function? Link to comment https://forums.phpfreaks.com/topic/154693-php-filtering/#findComment-813728 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.