I am new to the forums and I have a couple of questions. I have a PHP script that is needed to take information from a text file and converts that to needed information for our dealers. Our dealers mainly use ipads to check the inventory in our warehouses to show their customers, which is what the information is. The CSS and Jquery works fine, but the problem I am running into is that the script takes way to long to load the information that it is pulling from the text file. Which is
huge!
I know I will get a lot of responses that say I should put this into a PHP/SQL datatabase, but I'm just not sure how that will communicate with the program that generates this data. I do not think it is compatible. Also, is there anyway to make this more Ipad friendly? It takes even longer to load on the mobile devices.
Code: Select all
<?php
set_time_limit(0);
function csv_split($line,$delim=',',$removeQuotes=true) {
#$line: the csv line to be split
#$delim: the delimiter to split by
#$removeQuotes: if this is false, the quotation marks won't be removed from the fields
$fields = array();
$fldCount = 0;
$inQuotes = false;
for ($i = 0; $i < strlen($line); $i++) {
if (!isset($fields[$fldCount])) $fields[$fldCount] = "";
$tmp = substr($line,$i,strlen($delim));
if ($tmp === $delim && !$inQuotes) {
$fldCount++;
$i += strlen($delim)-1;
} else if ($fields[$fldCount] == "" && $line[$i] == '"' && !$inQuotes) {
if (!$removeQuotes) $fields[$fldCount] .= $line[$i];
$inQuotes = true;
} else if ($line[$i] == '"') {
if ($line[$i+1] == '"') {
$i++;
$fields[$fldCount] .= $line[$i];
} else {
if (!$removeQuotes) $fields[$fldCount] .= $line[$i];
$inQuotes = false;
}
} else {
$fields[$fldCount] .= $line[$i];
}
}
return $fields;
}
$html_body = '<html>....<tbody>'
$fp=fopen("csv/inventory4.html",'w');
$write=fputs($fp,$html_body,strlen($html_body));
$i=0;
$content = file("webinvt.txt");
foreach($content as $line)
{
$l=csv_split($line);
if(!strstr($l[11],"SET"))
{
if($i==7000)
{
$tmp = '<tr>';
$write=fputs($fp,$tmp,strlen($tmp));
$i=0;
}
$onhand = (int)$l[15];
$committed = (int)$l[16];
$avail = $onhand - $committed;
$wcdate = substr($l[23],4);
$eastdate = substr($l[19],4);
if(strstr($l[1],"DISC"))
{
$html_body ='<tr style="color:#FF0000">
<td>'.$l[0].'</td>
<td>'.$l[1].'</td>
<td>'.$l[12].'</td>
<td align="center">'.$avail.'</td>
<td>'.$l[17].'</td>
<td>'.$l[18].'</td>
<td>'.$eastdate.'</td>
<td>'.$l[21].'</td>
<td>'.$l[22].'</td>
<td>'.$wcdate.'</td>
</tr>';
}
else
{
$html_body ='<tr>
<td>'.$l[0].'</td>
<td>'.$l[1].'</td>
<td>'.$l[12].'</td>
<td align="center">'.$avail.'</td>
<td>'.$l[17].'</td>
<td>'.$l[18].'</td>
<td>'.$eastdate.'</td>
<td>'.$l[21].'</td>
<td>'.$l[22].'</td>
<td>'.$wcdate.'</td>
</tr>
';
}
$write=fputs($fp,$html_body,strlen($html_body));
$i++;
}
}
$html_body='
</tbody>
</table>
</div>
</body>
</html>';
$write=fputs($fp,$html_body,strlen($html_body));
fclose($fp);