Note that there are some explanatory texts on larger screens.

plurals
  1. POPhp loop and writing to MySql db
    primarykey
    data
    text
    <p>I'm having problems with the following script. It updates every selected field where the "state" field is ACTIVE with the values from the last pass. I only want it to update the field corresponding to the id field.</p> <p>LE. I have multiple records, but only certain of them are ACTIVE.</p> <pre><code>ID 1 state ACTIVE ID 2 state ACTIVE ID 3 state DONE </code></pre> <p>right now the script writes in the status and speed field the same value for ID 1 and 2. I want it to write only the corresponding values for each ID.</p> <p>Hope this clears it.</p> <pre><code>$result = mysql_query("SELECT id, filename, status, totalsize, procent, pid, log_no FROM plow WHERE state = 'Active'"); while (($db_field = mysql_fetch_array($result)) != false) { $cfs = filesize($init_loc."/".$db_field['filename']); $procentage= ($cfs * '100')/$db_field['totalsize']; $out1="2"; $pid2=$out1 + $db_field['pid']; $command = exec("ps ax | grep -v grep | grep -c ".$pid2, $out); exec($command, $out); if ($out[0] == 1 &amp;&amp; $procentage &lt;= 99 ) { $fp = fopen($init_loc."/Logs/log".$db_field['log_no'], 'r'); $cursor = -1; fseek($fp, $cursor, SEEK_END); $char = fgetc($fp); while ($char === "\n" || $char === "\r") { fseek($fp, $cursor--, SEEK_END); $char = fgetc($fp); } while ($char !== false &amp;&amp; $char !== "\n" &amp;&amp; $char !== "\r") { $line = $char . $line; fseek($fp, $cursor--, SEEK_END); $char = fgetc($fp); } $av_speed=ereg_replace("[^0-9]", "", substr($line,-6)); mysql_query("UPDATE plow SET currentsize = '$cfs', procent = '$procentage', av_speed = '$av_speed' WHERE id = '".$db_field['id']."'") or die ('Error: ' . mysql_error()); $needle1='Waiting'; $needle2='failed'; $needle3='no module'; $needle4='retry after a safety wait'; $search1=strpos($line, $needle1); $search2=strpos($line, $needle2); $search3=strpos($line, $needle3); $search4=strpos($line, $needle4); if($search1 !== false) { $status=ereg_replace("[^0-9]", "", $line); mysql_query("UPDATE plow SET status = '$status' WHERE id = '".$db_field['id']."'") or die ('Error: ' . mysql_error()); } elseif ($search2 !== false) { $status="2"; mysql_query("UPDATE plow SET status = '$status' WHERE id = '".$db_field['id']."'") or die ('Error: ' . mysql_error()); } elseif ($search3 !== false) { $status="2"; mysql_query("UPDATE plow SET status = '$status' WHERE id = '".$db_field['id']."'") or die ('Error: ' . mysql_error()); } elseif ($search4 !== false) { $status="Retrying ..."; mysql_query("UPDATE plow SET status = '$status' WHERE id = '".$db_field['id']."'") or die ('Error: ' . mysql_error()); } else { $status="3"; mysql_query("UPDATE plow SET status = '$status' WHERE id = '".$db_field['id']."'") or die ('Error: ' . mysql_error()); } unset($search1); unset($search2); unset($search3); unset($search4); unset($av_speed); unset($status); } else if ($out[0] == 0 &amp;&amp; $procentage == 100 ) { mysql_query("UPDATE plow SET currentsize = '$cfs', procent = '$procentage', status= '1', state = 'Done' WHERE id = '".$db_field['id']."'") or die ('Error: ' . mysql_error()); unset($status); } else { $status="Unknown error"; mysql_query("UPDATE plow SET status= '$status' WHERE id = '".$db_field['id']."'") or die ('Error: ' . mysql_error()); } } mysql_close(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload