php question

Discussion in 'PHP' started by izlik, Jan 25, 2010.

  1. #1
    in the code bellow every time my page is loaded $src becomes a random number. is it possible to incresse $src by one somehow ? so if it become 45 i want it to be incressed by one to 46.

    <? echo "/flash/loops/".basename($src).""; ?>
     
    izlik, Jan 25, 2010 IP
  2. chandan123

    chandan123 Prominent Member

    Messages:
    11,586
    Likes Received:
    578
    Best Answers:
    0
    Trophy Points:
    360
    #2
    how /where you initialize that $src variable ? is that global ?
     
    chandan123, Jan 25, 2010 IP
  3. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #3
    check the script bellow. it's a randomizing script a friend gave me. i want $src to become +1 and one place only the rest of the places it's displayed should stay the same number

    /* The default folder with images */
    $settings['img_folder'] = '/var/www/flash/loops/';
    /* File types (extensions) to display */
    $settings['img_ext'] = array('.jpg','.gif','.png','.swf');
    
    $settings['display_type'] = 0;
    
    /* Allow on-the-fly settings override? 0 = NO, 1 = YES */
    $settings['allow_otf'] = 1;
    
    /* Override type? */
    if ($settings['allow_otf'] && isset($_GET['type']))
    {
    	$type = intval($_GET['type']);
    }
    else
    {
    	$type = $settings['display_type'];
    }
    
    /* Override images folder? */
    if ($settings['allow_otf'] && isset($_GET['folder']))
    {
    	$folder = htmlspecialchars(trim($_GET['folder']));
        if (!is_dir($folder))
        {
        	$folder = $settings['img_folder'];
        }
    }
    else
    {
    	$folder = $settings['img_folder'];
    }
    
    /* Make sure images fodler ends with an '/' */
    if (substr($folder,-1) != '/')
    {
    	$folder.='/';
    }
    
    /* Get a list of all the image files */
    $flist = array();
    foreach($settings['img_ext'] as $ext)
    {
        $tmp = glob($folder.'*'.$ext);
        if (is_array($tmp))
        {
        	$flist = array_merge($flist,$tmp);
        }
    }
    
    /* If we have any images choose a random one, otherwise select the "noimg.gif" image */
    if (count($flist))
    {
    	$src = $flist[array_rand($flist)];
    }
    else
    {
    	$src = 'noimg.gif';
    }
    
    /* Output the image according to the selected type */
    if ($type)
    {
    	header('Location:'.$src);
        exit();
    }
    else
    {   
        $fruit   = array('apple', 'pear');
        $text    = 'a p';
        $output  = str_replace($letters, $fruit, $text);
    
    }
    ?>
    
    <? echo "/flash/loops/".basename($src).""; ?>
    
    Code (markup):
     
    izlik, Jan 25, 2010 IP
  4. Sam Designs

    Sam Designs Active Member

    Messages:
    474
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Replace $src = $flist[array_rand($flist)];

    with

    $src = $flist[array_rand($flist) + 1];

    I don't know why you'd want to do that, though.
     
    Sam Designs, Jan 25, 2010 IP
  5. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #5
    ah sorry let me remake the question. let's say i have this

    <? echo "/flash/loops/".basename($src).""; ?> and once the page load $src becomes 55. i want to have another link like this <a href="<? echo "/flash/loops/".basename($plus).""; ?>">next</a> <-- that one should have the +1 to it, so it's 56 insteed.
     
    izlik, Jan 25, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    Simply just add 1 (google "php addition operator") to $src. :p

    Heres a quick example :p

    
    <?php
    $basename = basename($src);
    $next = $basename + 1;
    ?>
    <a href="<?php echo "/flash/loops/".$next; ?>">next</a>
    
    PHP:
     
    Last edited: Jan 25, 2010
    danx10, Jan 25, 2010 IP