Jump to content

Recommended Posts

Well this function I created is supposed to read the data from a file into my database, but for some reason that I cannot see, it is stuck in an eternal loop.  it seems to go back to the beginning of the else statement everytime.  So when I use this function, it cycles through all of the rows and once it hits the last line it seems to go back to the beginning of the else statement and just do the whole process over and over again until I hit the stop button.  I hope that this is written clearly enough for everyone to understand.  If you don't understand what I am talking about, I will try to clear it up.

Here is my code:
[code]<?php
function read_fms_file($date){
$sql = "DELETE FROM payroll_dept_totals
        WHERE pdt_date = '$date'";
run_sql($sql) or die(mysql_error());
$file = "c:\\fms_data\\$date\sales_to_labor.txt";
if(!file_exists($file)) {
  $_SESSION['message'] = "File does not exist";
  return false;
}
else{
  $handle = fopen($file, "r");
  $contents = fread($handle, filesize($file));
  fclose($handle);
  $row = explode("\n", $contents);
  $rows = count($row);

  echo "1 ";
  $i = 0;
  //for($i = 0; $i < $rows-1; $i++) {
  while($i < $rows-1){
  $parts = explode(" ", $row[$i]);
  echo "2 ";
  unset($numbers);
  $numbers = array();
  foreach($parts as $part) {
    $part = trim($part);
    if(is_numeric($part)) {
    //echo "part = ".$part."|";
    echo"3 ";
array_push($numbers, $part);
}
  }
  echo "numbers = ".$numbers."    ";
  array_pop($numbers);
  array_pop($numbers);
  echo "4 ";
  $sql = "INSERT INTO payroll_dept_totals (pdt_store_id, pdt_dept_id,
                        pdt_oper_wages, pdt_oper_hours, pdt_ben_wages, pdt_ben_hours,
pdt_date)
      VALUES (";
  foreach($numbers as $number) {
    $sql .= "'$number',";
    echo "5 ";
    echo "5 ";
    //echo "number = ".$number."    ";
  }
  echo "6 ";
  echo "row = ".$i." ";
  $sql .= "'$date')";
  $result = run_sql($sql) or die(mysql_error());
  $i++;
  }
  //return true;
}
}
?>[/code]

sorry if the code is a little messy.

Thanks in advance for any help!!
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.