VTS Posted July 11, 2006 Share Posted July 11, 2006 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]<?phpfunction 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!! Quote Link to comment https://forums.phpfreaks.com/topic/14337-reading-data-into-a-database-loop-problem/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.