weird rand() issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

weird rand() issue

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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;
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply