getMostRecentPhotoURL

Hi everybody.

first, a big thank to the developers of ZenPhoto, it's exactly what I was looking for :)

second, it's exactly what I was looking for but it lacks a function for displaying the latest image uploaded (for a photoblog-like functionning).

that is because is wanted to display the most recent photo but also the galleries index. by the way, i'm french so it's normal if my english sounds weird ;)

so here the little code i had to templates_functions.php, line 92:

`

function getMostRecentPhotoURL() {

$host = '';

$user = '';

$pass = '';

$db = '';

$db_prefix = '';

$base_url = '';

//connexion à la base mysql

$con = mysql_connect($host, $user, $pass);

mysql_select_db($db,$con);

//trouver la photo la plus recente

$query = "SELECT * FROM ".$db_prefix."images ORDER BY id DESC LIMIT 1;";

$result = mysql_query($query);

//trouver son almbum

$query2 = "SELECT * FROM ".$db_prefix."albums WHERE id=".mysql_result($result,0,'albumid').";";

$result2 = mysql_query($query2);

// construction de l'url de l'image :)

$image = mysql_result($result,0,'filename');

$album = mysql_result($result2,0,'folder');

$path = $base_url."/albums/".$album."/".$image;

//afficher l'image

return $path;

}

`

it's not perfect but it works and i hope a zenphoto guru will replace the ugly parts (mysql connexion) with the nice zenphoto adequate functions :)

in my template, i use:

`

image" width="600"/>

`

i hope that will be useful to someone as zenphoto is useful to me. thx again guys :)

Comments

  • hey, me again. i had 15 minutes so i search in the .php files on zenphoto and i found the corresponding functions. here's a cleaner version:

    `

    function getMostRecentPhotoURL() {

    //trouver la photo la plus recente

    //find the most recent photo

    $query = "SELECT * FROM ".prefix("images")." ORDER BY id DESC LIMIT 1;";

    $result = query($query);

    //trouver son album

    //find the corresponding album

    $query2 = "SELECT * FROM ".prefix("albums")." WHERE id=".mysql_result($result,0,'albumid').";";

    $result2 = query($query2);

    //construction de l'url de l'image :)

    //computing the image's url

    $image = mysql_result($result,0,'filename');

    $album = mysql_result($result2,0,'folder');

    $path = FULLWEBPATH."/albums/".$album."/".$image;

    //afficher l'image

    return $path;

    }

    `

    do you see more improvement? perhaps about the mysql_result() calls?

Sign In or Register to comment.