PHP Code to Search for Unlisted Galleries

dalterdalter Registered Users Posts: 5 Beginner grinner
I am trying to use Colin Seymour's PHP wrapper, phpSmug to write a simple task of searching for the title of an unlisted gallery in order to generate album info and a direct link.

I'm not a professional PHP programmer and everything is working correctly except for searching the array for the title.

Does anyone have any suggestions on how to fix this code?

Thanks,
dalter

==============
<html>
<head>
<title>Album Title Search</title>
</head>
<body>

<?php

require_once("../phpSmug.php");
$hash = "XXXXXXXXXXXXXXXXXXXX.";
$title = "Some Album Title to Search For";


try {
$f = new phpSmug("APIKey=xxxxxxxxxxxxxxx", "AppName=Authorize Access");
$f->login("UserID=xxxxxxx", "PasswordHash=$hash");
$albums = $f->albums_get();

if (in_array(album('Title' => $title), $albums))
{
echo "Album ID: {$album} <br />";
echo "Album Key: {$album} <br /> ";
echo "Album Title: {$album} <br /> ";
echo "Category: {$album} <br /> ";

echo "<td><a href='http://USERNAME.smugmug.com/". $album . "/" . $album . "/" . $album . "_" . $album ."'>Go To Album</a></td><br /> ";
echo "<br />";

}
else
{
echo "No album found with that name";
}

}
catch (Exception $e) {
echo "{$e->getMessage()} (Error Code: {$e->getCode()})";
}
?>
</body>
</html>
====================

Comments

  • BeachBillBeachBill Registered Users Posts: 1,311 Major grins
    edited April 30, 2010
    dalter wrote:
    $albums = $f->albums_get();

    if (in_array(album('Title' => $title), $albums))
    {
    echo "Album ID: {$album} <br />";
    echo "Album Key: {$album} <br /> ";
    echo "Album Title: {$album} <br /> ";
    echo "Category: {$album} <br /> ";

    echo "<td><a href='http://USERNAME.smugmug.com/". $album . "/" . $album . "/" . $album . "_" . $album ."'>Go To Album</a></td><br /> ";
    echo "<br />";

    }

    Where did you get this syntax? Was it example code some where?
    Bill Gerrard Photography - Facebook - Interview - SmugRoom: Useful Tools for SmugMug
  • dalterdalter Registered Users Posts: 5 Beginner grinner
    edited April 30, 2010
    Hey BeachBill,

    It's been a few months since I worked on this code so I don't remember exactly where all the parts came from. The first half definitely came from the examples at phpSmug.

    If I replace the if/else statement with the following, it works perfectly at returning the info for every gallery returned in the array:

    ===================
    foreach ($albums as $album)
    {
    echo "Album ID: {$album} <br />";
    echo "Album Key: {$album} <br /> ";
    echo "Album Title: {$album} <br /> ";
    echo "Category: {$album} <br /> ";
    // echo "Sub Category: {$album} <br /> ";
    echo "<td><a href='http://hhv.smugmug.com/". $album . "/" . $album . "/" . $album . "_" . $album ."'>Go To Album</a></td><br /> ";
    echo "<br />";
    ===================

    I'm sure I must have some syntax issues with my if/else statement. I'm new to using multidimensional arrays in PHP.

    Thanks for taking a look,
    David
  • BeachBillBeachBill Registered Users Posts: 1,311 Major grins
    edited April 30, 2010
    First off, I have no idea what the following in your in_array is attempting to do:

    album('Title' => $title)

    Next, in_array, if it's coded correctly will only tell you if the value exists somewhere in the array, it will not tell you where. The logic inside your if will not return anything, or if it does, not what you are looking for.

    The easy solution is to put back the foreach to loop through the albums, then inside the foreach, add an if to test the value of $album against your $title value, if it matches, then output the album information.
    Bill Gerrard Photography - Facebook - Interview - SmugRoom: Useful Tools for SmugMug
Sign In or Register to comment.