Semi-Coppermine integration
-
Resolved
I’ve just started using WP so if I don’t code per the WP hack style, please correct me and I will change my stuff. I’m not 100% sure on how to use the myhacks.php file yet so I just did a direct index.php edit. Someone with more experience, please point out the mistakes so I can change accordingly.
The following code should be added to the menu section and will display a random image and its title from the coppermine gallery. It will also link the image to the album the image is in. You can see it working here: https://www.blog.jydesign.biz
Here’s the code :
<li id=”categories”>Photolog Image:-
<?php
function mysql_fetch_array_r($result, $index_row = “”, $fetch = MYSQL_ASSOC){
$i = 0;
while ($row = mysql_fetch_array($result,$fetch)){
$whole_result[$i] = $row;
$i++;
}
return $whole_result;
}
$server = “localhost”; //your coppermine db host
$db = “”; // your coppermine db name
$user = “”; // your coppermine db user
$pass = “”; // your coppermine db pass
$pictures_db = “cpg11d_pictures”; // your coppermine pictures db, typically cpg11d_pictures. look it up in phpmyadmin if you aren’t sure.
$link = mysql_connect ($server, $user, $pass);
if (!link) {
echo “Unable to connect to database”;
}
$db_selected = mysql_select_db($db, $link);
if (!$db_selected) {
echo “Unable to select image db ” . mysql_error();
}
$query = “SELECT MAX(pid) from ” . $pictures_db;
$query_result = mysql_query($query, $link);
$img_id = mysql_fetch_array($query_result);
$pid = rand(1, $img_id[‘MAX(pid)’]);
$final_query = “SELECT filepath, filename, title from ” . $pictures_db . ” where pid=” . $pid;
$final_result = mysql_query($final_query, $link);
$final_array = mysql_fetch_array_r($final_result);
$img_path = “/photos/albums/” . $final_array[0][‘filepath’] . “thumb_” . $final_array[0][‘filename’];
$link_query = “SELECT aid from ” . $pictures_db . ” where pid=” . $pid;
$link_temp_result = mysql_query($link_query, $link);
$link_temp_array = mysql_fetch_array($link_temp_result);
$aid = $link_temp_array[0][‘aid’];
$link_query = “SELECT MIN(pid) from ” . $pictures_db . ” where aid=” . $aid;
$link_temp_result = mysql_query($link_query, $link);
$link_temp_array = mysql_fetch_array($link_temp_result);
$min_pid = $link_temp_array[0];
$pos = $pid – $min_pid;
echo ‘‘ . ‘<div align=”center”> <img src=”‘ . $img_path . ‘” border=”0″><br>’;
echo $final_array[0][‘title’] . “</div>”;
?>Any comments and suggestions are welcome.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Semi-Coppermine integration’ is closed to new replies.