ZenphotoCMS Forum
getMostRecentPhotoURL - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: General support (https://forum.zenphoto.org/forum-4.html)
+--- Thread: getMostRecentPhotoURL (/thread-1490.html)



getMostRecentPhotoURL - teriiehina - 2007-06-18

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:

`

[img][/img]

`

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




getMostRecentPhotoURL - teriiehina - 2007-06-18

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?




getMostRecentPhotoURL - thinkdreams - 2007-06-18

You might want to try:

http://www.zenphoto.org/trac/wiki/ZenphotoHacks#LatestImagesCustomFunction

It seems to work very well.