Page 1 of 1

weird rand() issue

Posted: Thu Aug 11, 2005 9:16 am
by shiznatix
ok i have a function and i call it like this

Code: Select all

$arr = find_random_link_spot($arr, 'diet_patch.htm', 'Diet Patch Report', -1);
now the first few lines of this function look like this

Code: Select all

function find_random_link_spot($lines, $filename, $keys, $max)
{
    if ($max == 0)
        return $lines;

    $max = ($max == -1 ? count($lines) : $max);

    $random = rand(0, $max);
now if when i call the function with any number other than -1 the page looks like it loads but nothing changes like if i put in -1 then loaded the page then changed the -1 to 2 and hit refresh nothing happens, like it says the pages loads but there are no changes, even if i put like echo $max. it does not give me any error messages and if i try to view the page in IE with a value for $max anything but -1 it gives me a can not find page error. this makes absolutly no sence to me so any ideas is great

Posted: Mon Aug 15, 2005 9:54 am
by pickle
You've got a bracket mixed up:

This

Code: Select all

$max = ($max == -1 ? count($lines) : $max);
Should be this

Code: Select all

$max = ($max == -1) ? count($lines) : $max;