Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts

    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();
            }
        } 
    Last edited by dniwebdesign; 02-09-2010 at 05:17 AM.
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #2
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •