Jump to content

Recommended Posts

...if i limit the number of rows to 29 or less, then information from the two files that i have is loaded properly into the mysql table, but anything above that seems to cause the script to stop and the .php file loads up until that point...i don't have a blank page, but when i check my mysql table, it only has 29 rows...

 

...this is my script...

<?php

error_reporting(E_ALL);
ini_set("display_errors", 1);
  
$connection = mysql_connect($db_server, $dbuname, $db_password);
mysql_select_db($db_name);
$sql = "TRUNCATE TABLE `alldata`";
mysql_query($sql);

$fh = fopen($myFile, 'r');
$data = fread($fh, filesize($myFile));
$fh2 = fopen($myFile2, 'r');
$theData = fread($fh2, filesize($myFile2));

$Chunks = str_replace('"', '', "$data");
$Chunks = explode("\r\n", $data);
$acount = count($Chunks);

$wordChunks = str_replace('"', '', "$theData");
$wordChunks = explode("\r\n", $theData);
$bcount = count($wordChunks);

function letter_case($matches) {
  return strtoupper($matches[1]).strtolower($matches[2].$matches[3]);
  }
  
for($i = 0; $i < $acount; $i++){
list($page,$item_number_1,$size,$info,$pricing,$pine,$poplar,$red_oak,$white_oak,$alder,$fir,$hemlock,$maple,$cherry,$hickory,$mahogany,$lyptus,$brazillian_cherry,$beech,$maple_with_leaf,$mdf,$birch,$walnut) = split('[,]', $Chunks[$i]);
$species = "pine";$letter = "kp";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "poplar";$letter = "p";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "red_oak";$letter = "o";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}};
$species = "white_oak";$letter = "wo";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "alder";$letter = "a";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "fir";$letter = "f";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "hemlock";$letter = "he";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "maple";$letter = "m";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "cherry";$letter = "c";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "hickory";$letter = "hi";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "mahogany";$letter = "ma";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "lyptus";$letter = "ly";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "brazillian_cherry";$letter = "br";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "beech";$letter = "be";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "maple_with_leaf";$letter = "ml";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "mdf";$letter = "mdf";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "birch";$letter = "bi";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
$species = "walnut";$letter = "w";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++){list($n, $p) = split('[,]', $wordChunks[$s]);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){${$species} = $p;$s == $bcount;}}}; 
mysql_query("INSERT INTO alldata (page,item_number_1,size,info,pricing,pine,poplar,red_oak,white_oak,alder,fir,hemlock,
maple,cherry,hickory,mahogany,lyptus,brazillian_cherry,beech,maple_with_leaf,mdf,birch,walnut) VALUES('$page','$item_number_1',
'$size','$info','$pricing','$pine','$poplar','$red_oak','$white_oak','$alder','$fir','$hemlock','$maple','$cherry','$hickory',
'$mahogany','$lyptus','$brazillian_cherry','$beech','$maple_with_leaf','$mdf','$birch','$walnut')") or die('Error, query failed: '.mysql_error());
}
mysql_query("DELETE FROM alldata LIMIT 1");
fclose($fh);
fclose($fh2);
echo "Importing all the information is complete.<br>";
   ?>

 

...within my .CSV files, there is nothing there to cause the script to stop...and it's not a matter of dealing with a timeout, it takes no longer than 11 seconds and the half loaded page appears...

 

...as a side note, i know i should create a function for that one section of repeatedness, but i have yet to get anything working properly for that, anyways that is not my main concern...

Link to comment
https://forums.phpfreaks.com/topic/194079-page-stops-loading/
Share on other sites

...as you mentioned, i am now escaping special characters, as well i have modified some parts to help with filtering and such...as of right now it imports up to 62 rows, which is still quite short of the 1583 that i need...there are no error warnings of any kind being displayed...once again, from clicking on my link to when the half loaded page appears only takes about 15 seconds...

 

...my current code...

<?php
set_time_limit  (0);
$mtime = microtime();
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $starttime = $mtime; 

error_reporting(E_ALL);
ini_set("display_errors", 1);
   
$connection = mysql_connect($db_server, $dbuname, $db_password);
mysql_select_db($db_name);
$sql = "TRUNCATE TABLE `alldata`";
mysql_query($sql);

# file import information
$fh = fopen($myFile, 'r');
$data = fread($fh, filesize($myFile));
$fh2 = fopen($myFile2, 'r');
$theData = fread($fh2, filesize($myFile2));

# pages
$Chunks = str_replace('"', '', "$data");
$Chunks = explode("\r\n", $data);
$acount = count($Chunks);

# prices
$wordChunks = str_replace('"', '', "$theData");
$wordChunks = explode("\r\n", $theData);
$bcount = count($wordChunks);

# upper/lower case function filter for items from price file
function letter_case($matches) {
  return strtoupper($matches[1]).strtolower($matches[2].$matches[3]);
  }
  
# import info for each species - should be replaced with a function call  
for($i = 0; $i < $acount; $i++){
list($page,$item_number_1,$size,$info,$pricing,$pine,$poplar,$red_oak,$white_oak,$alder,$fir,$hemlock,$maple,$cherry,$hickory,$mahogany,$lyptus,$brazillian_cherry,$beech,$maple_with_leaf,$mdf,$birch,$walnut) = split('[,]', $Chunks[$i]);
$species = "pine";$letter = "kp";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "poplar";$letter = "p";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "red_oak";$letter = "o";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "white_oak";$letter = "wo";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "alder";$letter = "a";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "fir";$letter = "f";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "hemlock";$letter = "he";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "maple";$letter = "m";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "cherry";$letter = "c";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "hickory";$letter = "hi";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "mahogany";$letter = "ma";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "lyptus";$letter = "ly";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "brazillian_cherry";$letter = "br";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "beech";$letter = "be";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "maple_with_leaf";$letter = "ml";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "mdf";$letter = "mdf";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "birch";$letter = "bi";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
$species = "walnut";$letter = "w";if(${$species} == "y"){for($s = 0; $s < $bcount; $s++)if(strlen($wordChunks[$s]) > 1){{list($n, $p) = explode(",", $wordChunks[$s]);$n = htmlentities($n, ENT_QUOTES);$p = htmlentities($p, ENT_QUOTES);$check = preg_replace_callback('#([a-z]*)(.*)([a-z])#i', 'letter_case', $n);if($check == $item_number_1.$letter){$s = $bcount;${$species} = $p;}}}};
mysql_query("INSERT INTO alldata (page,item_number_1,size,info,pricing,pine,poplar,red_oak,white_oak,alder,fir,hemlock,
maple,cherry,hickory,mahogany,lyptus,brazillian_cherry,beech,maple_with_leaf,mdf,birch,walnut) VALUES('$page','$item_number_1',
'$size','$info','$pricing','$pine','$poplar','$red_oak','$white_oak','$alder','$fir','$hemlock','$maple','$cherry','$hickory',
'$mahogany','$lyptus','$brazillian_cherry','$beech','$maple_with_leaf','$mdf','$birch','$walnut')") or die('Error, query failed: '.mysql_error());
}
mysql_query("DELETE FROM alldata LIMIT 1");
fclose($fh);
fclose($fh2);
echo "Importing all information complete<br>";
$mtime = microtime();
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $endtime = $mtime;
   $totaltime = ($endtime - $starttime);
   echo "<br>This page was created in ".round($totaltime, 2)." seconds"; 
   ?>

 

...thanks again for your help...darwin

Link to comment
https://forums.phpfreaks.com/topic/194079-page-stops-loading/#findComment-1021976
Share on other sites

What exactly is your page displaying? Since you are not echoing anything until the code at the end runs, how do you know that the page is only half loaded?

 

What have you checked in the code to pin down what it is doing? Is the value in $acount correct?

 

Your INSERT query has no error checking or error reporting logic, so even if it fails, you will never know if or why. For what you are doing, you should echo mysql_error() if the mysql_query() statement ever returns a FALSE value.

Link to comment
https://forums.phpfreaks.com/topic/194079-page-stops-loading/#findComment-1021980
Share on other sites

...thank you for your response...my page is displaying everything up until the where the php begins the for loops to retrieve and insert information into the database...

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="../index.css">
</head>

<body style="background: #cccccc url('../images/hatch.gif'); text-align:center; margin:0px; padding: 0px;">

<center>
<div style="width:830px; margin:0px; padding-top:15px; background:url('../images/o1.png');">

<!--HEADER-->
<div style="width: 750px; height: 55px; padding-top:25px; border:1px solid #000; background:#201d19 url('../images/header.jpg');">
<a style="display:block; float:left; text-align:left; z-index:300; width:550px; height:30px; background:transparent; font-size:32px; padding-left:23px; font-family: Georgia; color: #fff;" href="http://www.distinctivewooddesigns.com">distinctive wood designs inc.</a>
</div>


<!--CONTENT-->
<div class="h">Update
<img src="../images/mark.gif" style="position:relative; top:1px; left:40px;"></img>
<img src="../images/mark.gif" style="position:relative; top:1px; left:60px;"></img>
<img src="../images/mark.gif" style="position:relative; top:1px; left:80px;"></img>
</div>
<div class="m" style="width:730px; height:auto; padding:10px 0px 10px 20px; z-index:0;">

1583<br>

 

...in regards to how i know what it is currently doing, i am 'manually' looking at the database to see what information has been inserted...as well, i have inserted an echo statement for $acount which is correct, 1583...in regards to echo mysql_error(), i do believe it is in there, unless have put it in the wrong spot...thank you for your help...

Link to comment
https://forums.phpfreaks.com/topic/194079-page-stops-loading/#findComment-1021984
Share on other sites

...apparently i am overloading something, but no warning is indicating that, i have now added session values to my code and am importing 50 rows at a time, no problems, sort of annoying having to reload the same page (automatically of course) so many times to get my over 1500 rows into my database...nonetheless thank you for your help in resolving this issue...darwin

Link to comment
https://forums.phpfreaks.com/topic/194079-page-stops-loading/#findComment-1022118
Share on other sites

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.