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.
Page 3 of 3 FirstFirst 123
Results 31 to 34 of 34
  1. #31
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts
    Hmm, think this will work but test it!

    PHP Code:
    <?php
    session_start
    ();
    error_reporting (E_ALL E_STRICT);
    $files = array();
    $path "images/"
    $sRedirectTo 'http://yoursite.com/index.php';
    $_SESSION['numQuestions'] = 2// Number of questions presented per session

    if (!isset($_SESSION['visited']))
    {
        
    $_SESSION['visited'] = array();
    }

    if (
    $dh = @opendir($path))
    {
        while (
    false !== ($file readdir($dh)))
        {
            if (
    $file != "." && $file != ".." && is_file($path $file))
            {
                
    $files[] = $path $file;
            }
        }
        
    closedir($dh);
        
    // mkay, here remove what's already been visited
        
    $aUnvisited array_diff($files$_SESSION['visited']);
        
    print_r($aUnvisited);
        if ((
    count($aUnvisited) > 0) && (count($aUnvisited) < $_SESSION['numQuestions']))
        {
            
    // Still have places to go
            
    shuffle($aUnvisited);
            
    $sToInclude array_shift($aUnvisited);
            
    $_SESSION['visited'][] = $sToInclude;
            include(
    $sToInclude);
        }
        else
        {
            
    // Everything has been visited.  Put your end case scenario here.
            
    if (count($aUnvisited) == 0
            {
                
    session_unset();
            }
            
    header('Location: ' $sRedirectTo);
            exit();
        }
    }
    else
    {
        
    printf("Could not open %s for reading" PHP_EOL$path);

    ?>
    Logic will get you from A to B. Imagination will take you everywhere.
    Albert Einstein

  2. #32
    New Coder
    Join Date
    May 2012
    Posts
    57
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by dan-dan View Post
    Hmm, think this will work but test it!

    PHP Code:
    <?php
    session_start
    ();
    error_reporting (E_ALL E_STRICT);
    $files = array();
    $path "images/"
    $sRedirectTo 'http://yoursite.com/index.php';
    $_SESSION['numQuestions'] = 2// Number of questions presented per session

    if (!isset($_SESSION['visited']))
    {
        
    $_SESSION['visited'] = array();
    }

    if (
    $dh = @opendir($path))
    {
        while (
    false !== ($file readdir($dh)))
        {
            if (
    $file != "." && $file != ".." && is_file($path $file))
            {
                
    $files[] = $path $file;
            }
        }
        
    closedir($dh);
        
    // mkay, here remove what's already been visited
        
    $aUnvisited array_diff($files$_SESSION['visited']);
        
    print_r($aUnvisited);
        if ((
    count($aUnvisited) > 0) && (count($aUnvisited) < $_SESSION['numQuestions']))
        {
            
    // Still have places to go
            
    shuffle($aUnvisited);
            
    $sToInclude array_shift($aUnvisited);
            
    $_SESSION['visited'][] = $sToInclude;
            include(
    $sToInclude);
        }
        else
        {
            
    // Everything has been visited.  Put your end case scenario here.
            
    if (count($aUnvisited) == 0
            {
                
    session_unset();
            }
            
    header('Location: ' $sRedirectTo);
            exit();
        }
    }
    else
    {
        
    printf("Could not open %s for reading" PHP_EOL$path);

    ?>
    Hmmm I have only this text showing on a blank background:

    Array ( [0] => questions/0014023.html [1] => questions/0011023.html [2] => questions/0003023.html [3] => questions/0001023.html [4] => questions/0008023.html [5] => questions/0016023.html [6] => questions/0002023.html [7] => questions/0013023.html [8] => questions/0015023.html [9] => questions/0006023.html [10] => questions/0010023.html [11] => questions/0005023.html [12] => questions/0007023.html [13] => questions/0009023.html [14] => questions/0020023.html [15] => questions/0018023.html [16] => questions/0004023.html [17] => questions/0012023.html [18] => questions/0019023.html [19] => questions/0017023.html )

  3. #33
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts
    Can you post any errors please. I noticed one thing. Try this:

    PHP Code:
    <?php
    session_start
    ();
    error_reporting (E_ALL E_STRICT);
    $files = array();
    $path "images/"
    $sRedirectTo 'http://yoursite.com/index.php';
    $_SESSION['numQuestions'] = 2// Number of questions presented per session

    if (!isset($_SESSION['visited']))
    {
        
    $_SESSION['visited'] = array();
    }

    if (
    $dh = @opendir($path))
    {
        while (
    false !== ($file readdir($dh)))
        {
            if (
    $file != "." && $file != ".." && is_file($path $file))
            {
                
    $files[] = $path $file;
            }
        }
        
    closedir($dh);
        
    // mkay, here remove what's already been visited
        
    $aUnvisited array_diff($files$_SESSION['visited']);
        
    print_r($aUnvisited);
        if ((
    count($aUnvisited) > 0) && (count($aUnvisited) < $_SESSION['numQuestions']))
        {
            
    // Still have places to go
            
    shuffle($aUnvisited);
            
    $sToInclude array_shift($aUnvisited);
            
    $_SESSION['visited'][] = $sToInclude;
            include(
    $sToInclude);
        }
        else
        {
            
    // Everything has been visited.  Put your end case scenario here.
            
    if ((count($aUnvisited) == 0) || ($_SESSION['numQuestions'] > count($aUnvisited))) 
            {
                unset(
    $_SESSION['visited']);
            }
            unset(
    $_SESSION['numQuestions']);
            
    header('Location: ' $sRedirectTo);
            exit();
        }
    }
    else
    {
        
    printf("Could not open %s for reading" PHP_EOL$path);

    ?>
    Edit: Just noticed another potential error so updated.
    Edit: Been updated again. One problem is that the remaining unanswered questions (over mulitple restarts) might be greater than the questions per page. For this it'll just reset like if there were none.
    Last edited by dan-dan; 07-03-2012 at 09:21 PM.
    Logic will get you from A to B. Imagination will take you everywhere.
    Albert Einstein

  4. #34
    New Coder
    Join Date
    May 2012
    Posts
    57
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by dan-dan View Post
    Can you post any errors please. I noticed one thing. Try this:

    PHP Code:
    <?php
    session_start
    ();
    error_reporting (E_ALL E_STRICT);
    $files = array();
    $path "images/"
    $sRedirectTo 'http://yoursite.com/index.php';
    $_SESSION['numQuestions'] = 2// Number of questions presented per session

    if (!isset($_SESSION['visited']))
    {
        
    $_SESSION['visited'] = array();
    }

    if (
    $dh = @opendir($path))
    {
        while (
    false !== ($file readdir($dh)))
        {
            if (
    $file != "." && $file != ".." && is_file($path $file))
            {
                
    $files[] = $path $file;
            }
        }
        
    closedir($dh);
        
    // mkay, here remove what's already been visited
        
    $aUnvisited array_diff($files$_SESSION['visited']);
        
    print_r($aUnvisited);
        if ((
    count($aUnvisited) > 0) && (count($aUnvisited) < $_SESSION['numQuestions']))
        {
            
    // Still have places to go
            
    shuffle($aUnvisited);
            
    $sToInclude array_shift($aUnvisited);
            
    $_SESSION['visited'][] = $sToInclude;
            include(
    $sToInclude);
        }
        else
        {
            
    // Everything has been visited.  Put your end case scenario here.
            
    if (count($aUnvisited) == 0
            {
                unset(
    $_SESSION['visited']);
            }
            unset(
    $_SESSION['numQuestions']);
            
    header('Location: ' $sRedirectTo);
            exit();
        }
    }
    else
    {
        
    printf("Could not open %s for reading" PHP_EOL$path);

    ?>
    Edit: Just noticed another potential error so updated.
    It doesn't give me any errors. It openes te question page window as usually but instead of randomly picked question page it shows me the same text as I posted.
    Here is the screenshot: http://dl.dropbox.com/u/13971705/screenshot.jpg


 
Page 3 of 3 FirstFirst 123

Tags for this Thread

Posting Permissions

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