...

View Full Version : Resolved Function not returning information...



dniwebdesign
02-09-2010, 04:13 AM
Hello,
I have the following function, which is suppose to grab an image (just the info is stored in the db, not the actual image) randomly and display it. However if the image file does not exist, to grab a different one and display it. Seems like a simple process, however, it doesn't 100% work. Every now and then it doesn't "return" the information. I call this function at the top of my page using $image = $webFront->randImage();. Now, the echo calls in the function will echo out the data, however when I try to use the $image variable in my main page, it has nothing. I am stumped, any ideas as to why this is?

function randImage() {
global $db;
$getImage = $db->aQuery("SELECT * FROM table ORDER BY RAND() LIMIT 1");
$theImage = mysql_fetch_array($getImage);
if(file_exists("rand/".$theImage["id"].".jpg")) {
echo $theImage["id"];
echo " -> ".$theImage["title"]." -> rand/".$theImage["id"].".jpg";
return $theImage;
}
else {
$this->randImage();
}
}

dniwebdesign
02-09-2010, 04:17 AM
Nevermind...
In my recurisve call once I added:

else {
$theImage = $this->randImage();
}
It was working fine.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum