StarChild Posted June 3, 2005 Report Share Posted June 3, 2005 I am using the Random photo function that was written by Wayne Kenna, http://www.kennaweb.com and modified by Jeff Grantham, http://genealogy.kb5wck.com , to work with standard TNG installation.It has been working fine on my website with TNG version 4. Now I have upgraded to version 5.0 and it still works. But with the addition of documents now added to the photos table, occassionally, I get a random document on my front page rather than a random photo.The original code excludes the living people by checking the living people flag. It reads as follows. // get a random photo (make sure we limit ourselves to folks not flagged as living $query = "SELECT $photolinks_table.personID, $photolinks_table.ordernum, $people_table.living, ( $photolinks_table.ID / $photolinks_table.ID ) * RAND( ) AS MyRandom FROM $photolinks_table, $people_table WHERE $photolinks_table.personID = $people_table.personID ORDER BY MyRandom DESC LIMIT 1 , 1"; $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query"); $row1 = mysql_fetch_assoc($result); mysql_free_result($result); I attempted to modify the lines to also check the document flag in the photos table. My attempt is as follows. // get a random photo (make sure we limit ourselves to folks not flagged as living or as documents $query = "SELECT $photolinks_table.personID, $photolinks_table.ordernum, $people_table.living, $photos_table.phototype, ( $photolinks_table.ID / $photolinks_table.ID ) * RAND( ) AS MyRandom FROM $photolinks_table, $people_table, $photos_table WHERE $photolinks_table.personID = $people_table.personID AND $people_table.living = 0 AND $photos_table.phototype = 0 ORDER BY MyRandom DESC LIMIT 1 , 1"; $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query"); $row1 = mysql_fetch_assoc($result); mysql_free_result($result); But it did not work, I have been trying to read up on the SELECT statement online, but I can't see where my error is.Does anyone have any idea where I am going wrong?Thanks for your help. Quote Link to comment Share on other sites More sharing options...
klooster Posted June 16, 2005 Report Share Posted June 16, 2005 I had the same problem. I asked Darrin about it.His answer was:"didn't write randomphoto.php, so I can't support it, but basically you just have to include the "phototype" field in the SELECT criteria, then if photoblock = 1, you have to include "showdocs=1"in the link."I tried it, but could not get it to work??Maybe you can try his advice!let me know if you succceedCees Kloosterman at http://www.kloosterman.be Quote Link to comment Share on other sites More sharing options...
klooster Posted June 16, 2005 Report Share Posted June 16, 2005 I have asked Jeff Grantham, http://genealogy.kb5wck.com , for a solution. H'll have a look at it and see what he can do.Cees Kloosterman Quote Link to comment Share on other sites More sharing options...
theKiwi Posted June 16, 2005 Report Share Posted June 16, 2005 I've modified the randomphoto.php a bit too - not to exclude documents, but to properly show them when clicked on since the URL to a document is different from the URL to a photo now...Instead of a single line to generate the $mycontent I now have this: if($row[phototype] == 1) { $mycontent = "<a href="$cms[url]showphoto.php?photoID=$row[photoID]&showdocs=1">".makeImg($photopath."/".$row[thumbpath],$max_height,$max_width,$row[description],"border='1'")."</a><p><b><span class="normal">$row[description]</span></b></p>"; }else { $mycontent = "<a href="$cms[url]showphoto.php?photoID=$row[photoID]">".makeImg($photopath."/".$row[thumbpath],$max_height,$max_width,$row[description],"border='1'")."</a><p><b><span class="normal">$row[description]</span></b></p>"; } in each of the positions depending on whether someone is living or not. This adds the &showdocs=1 to the end of the URL to show a document image full size if it has randomly chosen a document. In the Select statement (in two places) I now have this (you have to get the phototype to determine if it's a photo (phototype=0) or document (phototype=1) // get the details $query = "SELECT path, thumbpath, description, notes, ordernum, personID, phototype, $photos_table.photoID as photoID FROM $photos_table, $photolinks_table WHERE ($photos_table.photoID = "$row1[photoID]" OR (personID = "$row1[personID]" AND ordernum = "$row1[ordernum]")) AND $photos_table.photoID = $photolinks_table.photoID"; - I added phototype to the data to get so it can be tested to see if it's 1 or not.CheersRogerhttp://roger.LisaAndRoger.com Quote Link to comment Share on other sites More sharing options...
klooster Posted June 17, 2005 Report Share Posted June 17, 2005 Hi RogerI changed the script as suggested:Photos oke, butdocuments do show (thumbnail) and erro message:Warning: getimagesize(photos/) [function.getimagesize]: failed to open stream: Permission denied in c:wampwwwgenealogyrandom-photo.php on line 103 Quote Link to comment Share on other sites More sharing options...
theKiwi Posted June 17, 2005 Report Share Posted June 17, 2005 What does line 103 say? In my file it's this// ========================================================================= Actually I don't really understand what the function is doing - the script has always worked for me in one form or another, it just didn't always give the desired result. The changes I've made to it are for dealing with Living people, and now the change to have documents show up properly. Here is my entire file: <?php //======================================================================================================================== // randomphoto.php // Author: Wayne Kenna, www.kennaweb.com // This module is released into the public domain // // Displays a random photo from the TNG Genealogy database. Displays the photo's thumbnail and a link to the full size photo. // // 1/29/04 - Added logic to work around entries in the photos table that do not have a file name defined. This can happen on gedcom // imports. Also added logic to resize photos in the event the thumbnail image of the photo is too large. //This file modified by Jeff Grantham to detect if the user is logged in - if they are then it can show photos of living people, otherwise it only shows photos of not living people. //Additions by Roger Moffat to support the new URL style for photo documents (which have &showdocs=1 at the end of the URL now // //======================================================================================================================== include_once("config.php"); include_once("genlib.php"); tng_db_connect($database_host,$database_name,$database_username,$database_password) or exit; $max_height = 175; // the maximum height to use when displaying an image $max_width = 175; // the maximum width to use when displaying an image $photo_not_ok = 1; // flag for the while() loop $max_trys = 100; // maximum number of times we will try to find a good photo entry; this keeps us from looping forever $trys = 0; // $mycontent = ""; // text variable that will be displayed if( $currentuser ) { while ($photo_not_ok == 1) { $trys = $trys + 1; // get a random photo - for living or non living people $query = "SELECT $photolinks_table.personID, $photolinks_table.ordernum, $people_table.living, ( $photolinks_table.ID / $photolinks_table.ID ) * RAND( ) AS MyRandom FROM $photolinks_table, $people_table WHERE $photolinks_table.personID = $people_table.personID ORDER BY MyRandom DESC LIMIT 1 , 1"; $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query"); $row1 = mysql_fetch_assoc($result); mysql_free_result($result); // get the details $query = "SELECT path, thumbpath, description, notes, ordernum, personID, phototype, $photos_table.photoID as photoID FROM $photos_table, $photolinks_table WHERE ($photos_table.photoID = "$row1[photoID]" OR (personID = "$row1[personID]" AND ordernum = "$row1[ordernum]")) AND $photos_table.photoID = $photolinks_table.photoID"; $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query"); $row = mysql_fetch_assoc($result); mysql_free_result($result); // check to make sure a thumbnail defined and the file exists if ($row[thumbpath]!="" && file_exists("$rootpath$photopath/$row[thumbpath]")) { $photo_not_ok = 0; // photo ok to use if($row[phototype] == 1) { $mycontent = "<a href="$cms[url]showphoto.php?photoID=$row[photoID]&showdocs=1">".makeImg($photopath."/".$row[thumbpath],$max_height,$max_width,$row[description],"border='1'")."</a><p><b><span class="normal">$row[description]</span></b></p>"; }else { $mycontent = "<a href="$cms[url]showphoto.php?photoID=$row[photoID]">".makeImg($photopath."/".$row[thumbpath],$max_height,$max_width,$row[description],"border='1'")."</a><p><b><span class="normal">$row[description]</span></b></p>"; } if ($trys > $max_trys) { $mycontent = "Tried $trys times to find a photo - FAILED"; break; } } } }else { while ($photo_not_ok == 1) { $trys = $trys + 1; // get a random photo (make sure we limit ourselves to folks not flagged as living $query = "SELECT $photolinks_table.personID, $photolinks_table.ordernum, $people_table.living, ( $photolinks_table.ID / $photolinks_table.ID ) * RAND( ) AS MyRandom FROM $photolinks_table, $people_table WHERE $photolinks_table.personID = $people_table.personID AND $people_table.living = 0 ORDER BY MyRandom DESC LIMIT 1 , 1"; $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query"); $row1 = mysql_fetch_assoc($result); mysql_free_result($result); // get the details $query = "SELECT path, thumbpath, description, notes, ordernum, personID, phototype, $photos_table.photoID as photoID FROM $photos_table, $photolinks_table WHERE ($photos_table.photoID = "$row1[photoID]" OR (personID = "$row1[personID]" AND ordernum = "$row1[ordernum]")) AND $photos_table.photoID = $photolinks_table.photoID"; $result = mysql_query($query) or die ("$text[cannotexecutequery]: $query"); $row = mysql_fetch_assoc($result); mysql_free_result($result); // check to make sure a thumbnail defined and the file exists if ($row[thumbpath]!="" && file_exists("$rootpath$photopath/$row[thumbpath]")) { $photo_not_ok = 0; // photo ok to use if($row[phototype] == 1) { $mycontent = "<a href="$cms[url]showphoto.php?photoID=$row[photoID]&showdocs=1">".makeImg($photopath."/".$row[thumbpath],$max_height,$max_width,$row[description],"border='1'")."</a><p><b><span class="normal">$row[description]</span></b></p>"; }else { $mycontent = "<a href="$cms[url]showphoto.php?photoID=$row[photoID]">".makeImg($photopath."/".$row[thumbpath],$max_height,$max_width,$row[description],"border='1'")."</a><p><b><span class="normal">$row[description]</span></b></p>"; } if ($trys > $max_trys) { $mycontent = "Tried $trys times to find a photo - FAILED"; break; } } } } echo $mycontent."n"; // ========================================================================= // Function: makeImg() // // This function formats and returns a html <img> string using the specified demensions // Parameters: // $image The path to the image file // $hmax The maximum height to limit the image display to // $wmax The maximum width to limit the image display to // $alt The alternate text string to display over the image (optional) // $extra Additional formatting text to include in the <img> statement (optional) // // ========================================================================= function makeImg($image, $hmax, $wmax, $alt = "", $extra = "") { list($width, $height, $type, $attr) = getimagesize($image); $hscale = $height / $hmax; $wscale = $width / $wmax; if (($hscale > 1) || ($wscale > 1)) { $scale = ($hscale > $wscale)?$hscale:$wscale; } else { $scale = 1; } $newwidth = floor($width / $scale); $newheight= floor($height / $scale); return "<img width='$newwidth' height='$newheight' src='$image' alt='$alt' $extra>"; } ?> Quote Link to comment Share on other sites More sharing options...
klooster Posted June 17, 2005 Report Share Posted June 17, 2005 Thanks Roger,its working now, documents show oke (thumbnail and large picture) Quote Link to comment Share on other sites More sharing options...
theKiwi Posted June 17, 2005 Report Share Posted June 17, 2005 Cool.I noticed when it gave me a document that it was a ship passenger list for someone whose passage was paid by someone from Kalamazoo, Michigan. I live in Caledonia, MI - about 40 or so miles north of Kalamazoo.Are you aware of this sitehttp://data.wmgs.org/ which I run for the local Genealogical Society - including an index to over 500,000 Obituaries from Grand Rapids area papers since 1910? There are over 100 people with last name Kloosterman in this index.CheersRoger Quote Link to comment Share on other sites More sharing options...
klooster Posted June 18, 2005 Report Share Posted June 18, 2005 Hi Roger,Tnaks for that info, I will check it out! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.