0

Maybe someone can help with this because I am going crazy:

$action = $_GET['action'];
$items = rtrim($_POST['items'],",");
$sql = mysql_query("SELECT url, pid, log_no FROM plow WHERE id IN ($items)") or die ('Error: ' . mysql_error());

    if ($action == 'start') {
        while ($db_row = mysql_fetch_assoc($sql)) { 
            //random number for the log file name
            $random = mt_rand(1,500000);
            //log file name
            $out_file = $init_loc.'/Logs/log'.$random;
            // the command
            $command = exec("($path" . " nohup plowdown --temp-directory='$init_loc' -o '$init_loc' " . "'".$db_row['url']."' 2> " . "'$out_file' > /dev/null &);" . "echo $$;", $out); 
            exec($command, $out);
            mysql_query("UPDATE plow SET status = 'Pending...', state = 'Active', pid = '".$out[0]."', log_no = '$random' WHERE id IN ($items)") or die ('Error: ' . mysql_error());
        }
    }

Basically, when the start command is given, I want to be able to execute for every value from $db_row the action there, generate a random number for the log and store each on of them in their respective place in the MySql DB.

Right now it stores the same $random and $pid number for every value of $db_row.

Thanks, Cristian.

1 Answer 1

1

As you're updating all items using the in clause, the last one will update them all with your last random number,

' ... where id='.$row['id']

in your update clause will only update a single row at a time

(obviously you have add id to your SELECT statement as well)

Sign up to request clarification or add additional context in comments.

1 Comment

k. I've been going thru this for the last 2 hours, I didn't even bother to look there, because I knew that I wrote that code correctly ... in mind anyway ... Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.