Note that there are some explanatory texts on larger screens.

plurals
  1. POMy While loop is not working, why?
    primarykey
    data
    text
    <p>I have a question in relationship to loops in php. I am trying play actions with the elements of my array, always with the last one. To do this I need:</p> <p>1- To know my array is not empty.</p> <p>2- To pickup the last item name of my array. This is because I need it to execute the Step0.php script.</p> <p>3- To delete the last item of my array.</p> <p>I want to repeat this action until the value of my array is zero and go out to this loop.</p> <p>I tried this but I had not lucky. :-(</p> <p>Any idea?</p> <pre><code>$array2; $array1; $diffe_array = array_diff($array2, $array1); //CREATE THE CONDICTION $diffe=count($diffe_array); do { $lastone=end($diffe_array); require('./Step0.php'); $extract=array_pop($diffe_array); $diffe=count($diffe_array); print_r($diffe_array); } while ($diffe &gt; 0); echo 'JUST YOU HAVE 0 ITEMS IN YOUR ARRAY!!!!'; </code></pre> <p>To complete my question I think is necessary to have clear (with this example):</p> <p><strong>Step1</strong>.- I have $array2 like this:</p> <p>array2 ( [0] => 00004.csv [1] => 00007.csv [2] => 00005.csv [3] => 00003.csv [4] => 00002.csv [5] => 00001.csv [6] => 00006.csv [7] => 00000.csv ) </p> <p><strong>Step2</strong>.- I have &amp;array1 like this:</p> <p>array1 ( [0] => 00004.csv [1] => 00003.csv [2] => 00002.csv [3] => 00001.csv [4] => 00000.csv )</p> <p><strong>Step3</strong>.- I calculate diffe_array with array_diff($array2,$array1):</p> <p>diffe_array ( [1] => 00007.csv [2] => 00005.csv [6] => 00006.csv )</p> <p><strong>Step4</strong>.- I need create a loop to extract each item from my diffe_array and use it in my other script Step0.php (this script open the file with the same name of my last item in my diffe_array and share its info into a database). I need to do this until my diffe_array is empty, so it goes out form the loop. </p> <p>By the way, the content of Step0.php is:</p> <pre><code>&lt;?php function Conection() { if (!($link=pg_connect("host=xxxxx port=xxxx dbname=xxxxx user=xxxxx password=xxxxx"))) { echo "Error connecting to the database."; exit(); } return $link; } require_once('./process.php');//This is the before file $rute="/rute/to/my/file/"; $end= $rute.$lastone; $row = 0; $handle = fopen($end, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); $row++; echo '&lt;b&gt;&lt;br/&gt;&lt;br/&gt;'; $request = "insert into table(column1,column2,column3,column4) values("; for ($c=0; $c &lt; $num; $c++) { if ($c==($num-1)) $request = $request."'".$data[$c] . "'"; else $request = $request."'".$data[$c] . "',"; } $request = $request.");"; echo $request."&lt;br&gt;"; $union=Conection(); $result=pg_query($union, $request); pg_close($union); } fclose($handle); ?&gt; </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.
    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