Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-09-2010, 04:13 AM   PM User | #1
dniwebdesign
Regular Coder

 
dniwebdesign's Avatar
 
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
dniwebdesign is an unknown quantity at this point
Function not returning information...

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?
PHP Code:
    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();
        }
    } 
__________________
Dawson Irvine
CEO - DNI Web Design
http://www.dniwebdesign.com

Last edited by dniwebdesign; 02-09-2010 at 04:17 AM..
dniwebdesign is offline   Reply With Quote
Old 02-09-2010, 04:17 AM   PM User | #2
dniwebdesign
Regular Coder

 
dniwebdesign's Avatar
 
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
dniwebdesign is an unknown quantity at this point
Nevermind...
In my recurisve call once I added:
PHP Code:
        else {
            
$theImage $this->randImage();
        } 
It was working fine.
__________________
Dawson Irvine
CEO - DNI Web Design
http://www.dniwebdesign.com
dniwebdesign is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:19 PM.


Advertisement
Log in to turn off these ads.