Jump to content

How to add search feature and css to this table


jjf3
Go to solution Solved by jjf3,

Recommended Posts

How would I go about adding a search feature, css, and a hidden rows feature/next buttons to this table I have written in PHP? 

There are about 5000+ items listed in this table, so it's crucial that it's a fast search bar. Any help would be greatly appreciated. I was trying to use jquery but everything is messed up and the search + features don't show up. 

$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==10)
{
$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 ">
<td>'.$l[0].'</td>
<td>'.$l[1].'</td>
<td>'.$l[12].'</td>
<td>'.$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>'.$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> 
Edited by jjf3
Link to comment
Share on other sites

The easiest way I can think of would be to use DataTables, which is a jQuery plugin.

 

 

For some reason datatables doesn't seem to like html tables...Also all of my HTML is included inside a PHP variable called $html_body. This is causing me headaches. It goes into a table alright, but the whole thing is shown and none of the features from datatables works. 

Link to comment
Share on other sites

Just so long as your table that is getting printed out is formatted correctly, then the datatables should still work. Are you able to show me the HTML that is produced when you open this page? If you could copy and paste the whole HTML for the page, we'll work out what's going on.

 

Denno

Link to comment
Share on other sites

Just so long as your table that is getting printed out is formatted correctly, then the datatables should still work. Are you able to show me the HTML that is produced when you open this page? If you could copy and paste the whole HTML for the page, we'll work out what's going on.

 

Denno

http://forums.phpfreaks.com/topic/283504-input-csv-file-into-datatable/?do=findComment&comment=1456486

 

thank you sooo much. Its actually posted on another topic here. The link is above!

Link to comment
Share on other sites

Can you actually copy and paste the HTML over from a rendered page? Saves me having to set up the script and get it rendering myself. Just open the page, view the source, then copy and paste it all here.

<?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>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="/css/demo_page.css">
<link rel="stylesheet" type="text/css" href="/css/demo_table.css">

<title>CSV Contents</title>
<style type="text/css">
<!--
.style5 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; }
.style9 {font-size: 12px}
.logo h1 {position: absolute; top: 5px; right: 5px; font-size:14px; }
.logo img-with-text {float: left; left 5px; font-size:14px;
.img-with-text {text-align: justify; width: 40%; height: 20%;}
.img-with-text img {display: block; margin: 0 auto;}
.search {margin : 0px;}



-->
</style>

<script class="jsbin" src="http://datatables.net/download/build/jquery.dataTables.nightly.js"></script>
<script type="text/javascript" language="javascript" src="/js/jquery.js"></script>


<div class="img-with-text">
<img src="/image002.png" alt="sometext" />
<p>WC" is West Coast warehouse- please add approximately 2-3 weeks for the arrival to East Coast.<br><br>
</p>

</div>

<div class="logo">
<br>Last Updated on '.date("F j, Y, g:i a",time()+3600).'


</h1>
</div>



</head>


<body id="dt_example">
<div id="container">
<h1> Check Inventory Here</h1>

<table>
<thead>
<tr>
<th>Item No</th>
<th>Description</th>
<th>Price</th>
<th>Available</th>
<th>Back Ordered</th>
<th>On Order</th>
<th>ETA WH</th>
<th>WC On Hand</th>
<th>WC On Ord</th>
<th>WC Order Date</th>





</tr>
</thead>
<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==10)
{
$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 ">
<td>'.$l[0].'</td>
<td>'.$l[1].'</td>
<td>'.$l[12].'</td>
<td>'.$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>'.$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>
<tfoot>
<tr>
<th>Item No</th>
<th>Description</th>
<th>Price</th>
<th>Available</th>
<th>Back Ordered</th>
<th>On Order</th>
<th>ETA WH</th>
<th>WC On Hand</th>
<th>WC On Ord</th>
<th>WC Order Date</th>
</tr>
</tfoot>
</table>
</body>
</html>';

$write=fputs($fp,$html_body,strlen($html_body));

fclose($fp);


?>
Link to comment
Share on other sites

Mate that's the PHP file. If you copy the source of the webpage, there will be no PHP in it. I just want to look at the finished product, not the script that makes it. I'll look at that later.

 

I am soooo sorry I must of read your post wrong or something. I cannot give you the entire contents because there is confidential information in it, but I'll give you the jist of it. 

 

<html>
<head>


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


<title>CSV Contents</title>
<link rel="stylesheet" type="text/css" href="/css/demo_page.css" />
<link rel="stylesheet" type="text/css" href="/css/demo_table.css" />


<style type="text/css">
<!--
.style5 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; }
.style9 {font-size: 12px}
.logo h1 {position: absolute; top: 5px; right: 5px; font-size:14px; }
.logo img-with-text {float: left; left 5px; font-size:14px;
.img-with-text {text-align: justify; width: 40%; height: 20%;}
.img-with-text img {display: block; margin: 0 auto;}
.search {margin : 0px;}






-->
</style>
<script src="/js/jquery.js"></script>
<script src="/js/jquery.dataTables.nightly.js"></script>




<div class="img-with-text">
    <img src="/csv/image002.png" alt="sometext" />
  <p>WC" is West Coast warehouse- please add approximately 2-3 weeks for the arrival to East Coast.<br><br>
  </p>


</div>


<div class="logo">
<br>Last Updated on November 5, 2013, 6:15 pm
</h1>
</div>






</head>




  <body id="dt_example">
    <div id="container">
       <h1>Check Inventory Here</h1>
 <table>
        <thead>
          <tr>
            <th>Item No</th>
            <th>Description</th>
            <th>Price</th>
            <th>Available</th>
            <th>Back Ordered</th>
             <th>On Order</th>
            <th>ETA WH</th>
            <th>WC On Hand</th>
            <th>WC On Ord</th>
            <th>WC Order Date</th>






            


          </tr>
        </thead>
        <tbody>
<tr>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
   
</tr> 
<tr>
<td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>


      </tr> 


    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    * 50000 more rows of stuff!




      </tr> 
</tbody>
<tfoot>
<tr>
           <th>Item No</th>
            <th>Description</th>
            <th>Price</th>
            <th>Available</th>
            <th>Back Ordered</th>
             <th>On Order</th>
            <th>ETA WH</th>
            <th>WC On Hand</th>
            <th>WC On Ord</th>
            <th>WC Order Date</th>
          </tr>
        </tfoot>
        </table>
        </body>
        </html>
        
Link to comment
Share on other sites

Few things with your code. You have output in the <head> tags. This isn't a header tag, this is for document information, so you should remove the code from the head tags, and place it in either a div with id/class of header, or inside <header> tags that are inside the body tags.

 

You also have an ending </h1> tag, but no opening <h1> tag. There are multiple divs that either aren't opened, or aren't closed.

 

So you're going to need to clean up your code/output a fair bit, and once you've done that, you'll get something like this: http://jsfiddle.net/Gd9QW/

 

That works with the datatables. It looks terrible, there is no CSS, but it works. Change some of the content in the table cells, and you'll see the sorting work when you click on the column headers.

 

Denno

Link to comment
Share on other sites

Few things with your code. You have output in the <head> tags. This isn't a header tag, this is for document information, so you should remove the code from the head tags, and place it in either a div with id/class of header, or inside <header> tags that are inside the body tags.

 

You also have an ending </h1> tag, but no opening <h1> tag. There are multiple divs that either aren't opened, or aren't closed.

 

So you're going to need to clean up your code/output a fair bit, and once you've done that, you'll get something like this: http://jsfiddle.net/Gd9QW/

 

That works with the datatables. It looks terrible, there is no CSS, but it works. Change some of the content in the table cells, and you'll see the sorting work when you click on the column headers.

 

Denno

 

 

$(document).ready(function () {
$('#example').dataTable();
});

Thank you sooo much, it really is a life saver. I will try this out at work tomorrow. Funny as I was copying the text over to here, I caught a missing Div or two myself. Now I have a new way of error checking. The only question that I have remaining is, do you think the Divs are the reason for the document.ready function working not quite right? I use Sublime Text 2 for my editor and it always shows an error when I place in this piece of code:

 

This goes on the php page. I have tried to end the $html_body variable by using

': 

but it doesn't even update then... 

Edited by jjf3
Link to comment
Share on other sites

You can put

$(document).ready(function () {

$('#example').dataTable();

});

anywhere you want. You can put it in script tags in your document header (in between the <head> tags), you can put it in your body in between <script> tags, but ideally you'd have it in an external JS file. If you don't already have an external JS file, I would suggest adding it to the end of your <body>

E.g.

<!-- Rest of your page -->
<script>
$(document).ready(function () {

   $('#example').dataTable();

});
</script>
</body>
</html>

Obviously make sure you give the table a valid id, and use that in place of 'example', and also make sure the datatables script is being imported correctly.

 

Denno

Link to comment
Share on other sites

You can put

$(document).ready(function () {

$('#example').dataTable();

});

anywhere you want. You can put it in script tags in your document header (in between the <head> tags), you can put it in your body in between <script> tags, but ideally you'd have it in an external JS file. If you don't already have an external JS file, I would suggest adding it to the end of your <body>

E.g.

<!-- Rest of your page -->
<script>
$(document).ready(function () {

   $('#example').dataTable();

});
</script>
</body>
</html>

Obviously make sure you give the table a valid id, and use that in place of 'example', and also make sure the datatables script is being imported correctly.

 

Denno

 

 

OK Thank you! I will try adding it in the morning and let you know how it goes. After I clean up the HTML a bit I plan on, using the document ready function in a separate .js file. 

 

So then, all I would have to add is, right?: 

<script src="/js/makedatatablesworkfunction.js"></script>

Also for the table. Would the code look something like this? 

 

 

<table id="inventory">
        <thead>
          <tr>
            <th>Item No</th>

ETC

ETC

Rest of HTML.

Then in the makedatatablesworkfunction.js file change it from example to inventory like so:

$(document).ready(function () {

   $('#inventory').dataTable();

});
Link to comment
Share on other sites

Yep you're spot on there.

 

Good Luck

 

Ok, i got that to work, partially. I got to put 8 rows of data in a table, but none of the rest appeared and the drop down and next buttons did not work. It only registered 8 entries. Datatables uses css classes for each row. I have options of: 

class="odd gradeA"
class="even gradeA"
class="even gradeC"
class="gradeA"

For Datatables how should I go about alternating between these in PHP? Take a look at the source code for the datatables example on their website for an example of what I am talking about. Also I had the datatable working but after I changed something I cannot get it back again. The features have since disappeared. 

 

HTML Output currently:
<html>
<head>


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


<title>CSV Contents</title>
<link rel="stylesheet" type="text/css" href="/css/demo_page.css" />
<link rel="stylesheet" type="text/css" href="/css/demo_table.css" />


<style type="text/css">
<!--
.style5 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; }
.style9 {font-size: 12px}
.logo h1 {position: absolute; top: 5px; right: 5px; font-size:14px; }
.logo img-with-text {float: left; left 5px; font-size:14px;
.img-with-text {text-align: justify; width: 40%; height: 20%;}
.img-with-text img {display: block; margin: 0 auto;}
.search {margin : 0px;}






-->
</style>
<script src="/js/jquery.js"></script>
<script src="/js/jquery.dataTables.nightly.js"></script>

<script src="/js/makedatatablesworkfunction.js"></script>




<div class="img-with-text">
    <img src="/csv/image002.png" alt="sometext" />
  <p>"WC" is West Coast warehouse- please add approximately 2-3 weeks for the arrival to East Coast.<br><br>
  </p>


</div>


<div class="logo">
<br>Last Updated on November 5, 2013, 6:15 pm
</h1>
</div>
</head>
  <body id="dt_example">
    <div id="container">
       <h1>Check Inventory Here</h1>
 <table cellpadding="0" cellspacing="0" border="0" class="display" id="inventory" width="100%">
        <thead>
          <tr>
            <th>Item No</th>
            <th>Description</th>
            <th>Price</th>
            <th>Available</th>
            <th>Back Ordered</th>
             <th>On Order</th>
            <th>ETA WH</th>
            <th>WC On Hand</th>
            <th>WC On Ord</th>
            <th>WC Order Date</th>
          </tr>

        </thead>
<tfoot>
<tr>
           <th>Item No</th>
            <th>Description</th>
            <th>Price</th>
            <th>Available</th>
            <th>Back Ordered</th>
             <th>On Order</th>
            <th>ETA WH</th>
            <th>WC On Hand</th>
            <th>WC On Ord</th>
            <th>WC Order Date</th>
          </tr>
        </tfoot>
        </thead>
        <tbody>
<tr>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
   
</tr> 
<tr>
<td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>
    <td>stuff</td>


      </tr> 


    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    * 50000 more rows of stuff!




      </tr> 
</tbody>

        </table>
        </div>
        </body>
        </html>

And Here is the PHP:
 
 
I use '; to escape after the first <tbody> so that I can include the following PHP code: 

 

'; $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==10)
  {
    $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>
    <td>'.$l[0].'</td>
    <td>'.$l[1].'</td>
    <td>'.$l[12].'</td>
    <td>'.$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>'.$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);

?>       

Where did I mess up here? It also loads slow because we have so much items, but I'm guessing this is a formatting issue and datatables should be able to handle 5000 items. 

Edited by jjf3
Link to comment
Share on other sites

Ok so I just looked at your first bit of code, as I didn't know what you meant by using the semi-colon for escaping. What you're actually doing is using the semi-colon to end the line for the string input of the html_body variable.

 

To be honest, it's quite hard to follow your code. And also, I hope that that isn't the current HTML output, because you still have divs in the <head> tags.

 

Can you attach your webinvt.txt file so I can actually run the script and see the output myself.

 

Have you considered using a database? It would make this much easier, and I would think much quicker too, as you don't have to handle external files.

Link to comment
Share on other sites

Ok so I just looked at your first bit of code, as I didn't know what you meant by using the semi-colon for escaping. What you're actually doing is using the semi-colon to end the line for the string input of the html_body variable.

 

To be honest, it's quite hard to follow your code. And also, I hope that that isn't the current HTML output, because you still have divs in the <head> tags.

 

Can you attach your webinvt.txt file so I can actually run the script and see the output myself.

 

Have you considered using a database? It would make this much easier, and I would think much quicker too, as you don't have to handle external files.

 

Quite right, I forgot to add the </head> into the code on here. On the site it's there. Right before: <body id="dt_example">. Are you saying I should move the </head> to before the logo? 

 

I cannot attach the webinvt.txt. That is confidential information. However, you can make a txt file with "stuff," X20 on one row and multiply that by 5000 rows to get a general idea of what is going on in there.  

 

How would I be able to convert this to a database without messing up current operations and php scripts? 

Link to comment
Share on other sites

So you have 20 elements on a line? I assume comma separated?

 

As for your <head> tag, the following if part of the HTML that you just pasted before

<html>

<head>





<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">





<title>CSV Contents</title>

<link rel="stylesheet" type="text/css" href="/css/demo_page.css" />

<link rel="stylesheet" type="text/css" href="/css/demo_table.css" />





<style type="text/css">

<!--

.style5 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; }

.style9 {font-size: 12px}

.logo h1 {position: absolute; top: 5px; right: 5px; font-size:14px; }

.logo img-with-text {float: left; left 5px; font-size:14px;

.img-with-text {text-align: justify; width: 40%; height: 20%;}

.img-with-text img {display: block; margin: 0 auto;}

.search {margin : 0px;}













-->

</style>

<script src="/js/jquery.js"></script>

<script src="/js/jquery.dataTables.nightly.js"></script>



<script src="/js/makedatatablesworkfunction.js"></script>









<div class="img-with-text">

    <img src="/csv/image002.png" alt="sometext" />

  <p>"WC" is West Coast warehouse- please add approximately 2-3 weeks for the arrival to East Coast.<br><br>

  </p>





</div>





<div class="logo">

<br>Last Updated on November 5, 2013, 6:15 pm

</h1>

</div>

</head> <!-- ========================== Notice the ending head tag here ======================== -->

  <body id="dt_example">

    <div id="container">

This is where it needs to be:

<html>

<head>





<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">





<title>CSV Contents</title>

<link rel="stylesheet" type="text/css" href="/css/demo_page.css" />

<link rel="stylesheet" type="text/css" href="/css/demo_table.css" />





<style type="text/css">

<!--

.style5 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; }

.style9 {font-size: 12px}

.logo h1 {position: absolute; top: 5px; right: 5px; font-size:14px; }

.logo img-with-text {float: left; left 5px; font-size:14px;

.img-with-text {text-align: justify; width: 40%; height: 20%;}

.img-with-text img {display: block; margin: 0 auto;}

.search {margin : 0px;}













-->

</style>

<script src="/js/jquery.js"></script>

<script src="/js/jquery.dataTables.nightly.js"></script>



<script src="/js/makedatatablesworkfunction.js"></script>







</head><!-- =========New </head> tag position=============== -->

<div class="img-with-text">

    <img src="/csv/image002.png" alt="sometext" />

  <p>"WC" is West Coast warehouse- please add approximately 2-3 weeks for the arrival to East Coast.<br><br>

  </p>





</div>





<div class="logo">

<br>Last Updated on November 5, 2013, 6:15 pm

</h1>

</div>

<!-- =========Old </head> tag position=============== -->

  <body id="dt_example">

    <div id="container">
Link to comment
Share on other sites

 

So you have 20 elements on a line? I assume comma separated?

 

As for your <head> tag, the following if part of the HTML that you just pasted before

<html>

<head>





<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">





<title>CSV Contents</title>

<link rel="stylesheet" type="text/css" href="/css/demo_page.css" />

<link rel="stylesheet" type="text/css" href="/css/demo_table.css" />





<style type="text/css">

<!--

.style5 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; }

.style9 {font-size: 12px}

.logo h1 {position: absolute; top: 5px; right: 5px; font-size:14px; }

.logo img-with-text {float: left; left 5px; font-size:14px;

.img-with-text {text-align: justify; width: 40%; height: 20%;}

.img-with-text img {display: block; margin: 0 auto;}

.search {margin : 0px;}













-->

</style>

<script src="/js/jquery.js"></script>

<script src="/js/jquery.dataTables.nightly.js"></script>



<script src="/js/makedatatablesworkfunction.js"></script>









<div class="img-with-text">

    <img src="/csv/image002.png" alt="sometext" />

  <p>"WC" is West Coast warehouse- please add approximately 2-3 weeks for the arrival to East Coast.<br><br>

  </p>





</div>





<div class="logo">

<br>Last Updated on November 5, 2013, 6:15 pm

</h1>

</div>

</head> <!-- ========================== Notice the ending head tag here ======================== -->

  <body id="dt_example">

    <div id="container">

This is where it needs to be:

<html>

<head>





<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">





<title>CSV Contents</title>

<link rel="stylesheet" type="text/css" href="/css/demo_page.css" />

<link rel="stylesheet" type="text/css" href="/css/demo_table.css" />





<style type="text/css">

<!--

.style5 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; }

.style9 {font-size: 12px}

.logo h1 {position: absolute; top: 5px; right: 5px; font-size:14px; }

.logo img-with-text {float: left; left 5px; font-size:14px;

.img-with-text {text-align: justify; width: 40%; height: 20%;}

.img-with-text img {display: block; margin: 0 auto;}

.search {margin : 0px;}













-->

</style>

<script src="/js/jquery.js"></script>

<script src="/js/jquery.dataTables.nightly.js"></script>



<script src="/js/makedatatablesworkfunction.js"></script>







</head><!-- =========New </head> tag position=============== -->

<div class="img-with-text">

    <img src="/csv/image002.png" alt="sometext" />

  <p>"WC" is West Coast warehouse- please add approximately 2-3 weeks for the arrival to East Coast.<br><br>

  </p>





</div>





<div class="logo">

<br>Last Updated on November 5, 2013, 6:15 pm

</h1>

</div>

<!-- =========Old </head> tag position=============== -->

  <body id="dt_example">

    <div id="container">

thanks I'll work on it tomorrow and yes I have 20 elements on a line. They are seperated by , and "". So it would look like, "stuff", "stuff" etc...

Edited by jjf3
Link to comment
Share on other sites

Ok so I just looked at your first bit of code, as I didn't know what you meant by using the semi-colon for escaping. What you're actually doing is using the semi-colon to end the line for the string input of the html_body variable.

 

To be honest, it's quite hard to follow your code. And also, I hope that that isn't the current HTML output, because you still have divs in the <head> tags.

 

Can you attach your webinvt.txt file so I can actually run the script and see the output myself.

 

Have you considered using a database? It would make this much easier, and I would think much quicker too, as you don't have to handle external files.

 

So it works perfect locally with only the HTML, something within my PHP is messing it up! I don't think the document ready function works on the PHP file, but the PHP file re-writes the HTML every two hours. I'm thinking if there is a way to place the function on the HTML page without it being rewritten, then that would solve everything. Though I'm not certain. 

 

I'm not sure what I did to get the 8 rows to appear in the data table at first, but on the site, I haven't been able to re-create the features again. All the HTML is in the right spot.

 

Although I do have a question about this last bit: Does this look right to you? 

  $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);


?>
Edited by jjf3
Link to comment
Share on other sites

Ok so I just looked at your first bit of code, as I didn't know what you meant by using the semi-colon for escaping. What you're actually doing is using the semi-colon to end the line for the string input of the html_body variable.

 

To be honest, it's quite hard to follow your code. And also, I hope that that isn't the current HTML output, because you still have divs in the <head> tags.

 

Can you attach your webinvt.txt file so I can actually run the script and see the output myself.

 

Have you considered using a database? It would make this much easier, and I would think much quicker too, as you don't have to handle external files.

 

OK I figured it out! It's a mixture of the PHP and the HTML The HTML produces an extra <tr> after every ten rows. This obviously displaces the other rows inside the datatable. How would I go about eliminating this output? See this code: 

if($i==10)
  {
    $tmp = '<tr>';
    $write=fputs($fp,$tmp,strlen($tmp));
    $i=0;
  }

inside the rest of the PHP code: 


$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==10)
  {
    $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>
    <td>'.$l[0].'</td>
    <td>'.$l[1].'</td>
    <td>'.$l[12].'</td>
    <td>'.$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>'.$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);


?>

Look for the second <tr> at the end of this HTML code:

<tr>
                    <td>other</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                </tr>
                <tr>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                </tr>
                <tr>
                    <td>other</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                </tr>
                <tr>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                </tr>
                <tr>
                    <td>other</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                </tr>
                <tr>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                </tr>
                <tr>
                    <td>other</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                </tr>
                <tr>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                </tr>
                 <tr>
                    <td>other</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                </tr>
                <tr>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    <td>stuff</td>
                    </tr><tr><tr> 
                    <td>more stuff</td>
*
*
*
ETC
ETC

            
Edited by jjf3
Link to comment
Share on other sites

Ok, so what is the significance of the 10? Why are you counting to 10?

 

I really need to know the structure of your webinvt.txt file if I'm going to be able to run any tests myself.. Just putting 'stuff' in there won't work, as you're echoing out array indexes of strings, which means it's only going to grab a single letter, which would actually be a number from the real data I would assume.

 

To be honest, this is really a terrible way to manage your inventory, it's exceptionally clunky and nearly impossible to maintain.

 

I suggest you put your efforts into a writing a script that will parse your webinvt.txt file, and instead of writing it to a html file, save it to a database. You can then use phpmyadmin to manage the values in the database, or you could write your own, very basic, CMS (content management system).

 

But as I said, without knowing what each field in your txt file is supposed to be (they're not going to all be strings), it's incredibly hard for me to give you definitive help, without just throwing guesses at you..

Link to comment
Share on other sites

Ok, so what is the significance of the 10? Why are you counting to 10?

 

I really need to know the structure of your webinvt.txt file if I'm going to be able to run any tests myself.. Just putting 'stuff' in there won't work, as you're echoing out array indexes of strings, which means it's only going to grab a single letter, which would actually be a number from the real data I would assume.

 

To be honest, this is really a terrible way to manage your inventory, it's exceptionally clunky and nearly impossible to maintain.

 

I suggest you put your efforts into a writing a script that will parse your webinvt.txt file, and instead of writing it to a html file, save it to a database. You can then use phpmyadmin to manage the values in the database, or you could write your own, very basic, CMS (content management system).

 

But as I said, without knowing what each field in your txt file is supposed to be (they're not going to all be strings), it's incredibly hard for me to give you definitive help, without just throwing guesses at you..

IDK, I think that's just the way the table was set up. I inherited this project a couple of months ago. This was created three years ago and nobody quite knows how it works, so it's up to me to figure it out. That's why I was hired! So that being said, You don't need what's in the txt file, and anyway as I said before, that info is confidential. I cannot give it out, but it shouldn't matter what you put in the txt file. 

 

We get this information from a program that simulates a unix environment. I think the only output they have available is text. All of this information is taken from that program. What I don't know is the capabilities of that environment, and if it can even handle a database like that. I'm just giving you the background of our setup here. You probably won't be able to help out much here. I'm going to try increasing the row count by 6000 and see if that works.Seeing that we don't even have 6000 items it should eliminate that <tr>

Edited by jjf3
Link to comment
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.