Jump to content

jjf3

Members
  • Posts

    20
  • Joined

  • Last visited

Posts posted by jjf3

  1. 1. @jjf3, you have been asked what the structure of this data is, not for actual data. your code implies there's at least 24 fields (0-23) to a line (you were asked if there were 20 and you confirmed the 20 value), some with specific prefixes. no one here is going to sift through the code (which is questionable code anyway with things like the if($i==10) in it) to reverse engineer what the format of the data in the file looks like in order to make up some test data that matches what the code expects.

     

    if you want specific help, take a line of your actual data and alter the sensitive data part of it and post it.

    My apologies.

     

    1. I thought that's what I was doing. I just told denno020 that if he wanted to create the webinvt.txt file himself he should just input about 20 elements of w/e. I only used "stuff" as an example in place of the sensitive data which is located in the webinvt. He seems to want the data in the txt file which is irrelevant to the problem. 

     

     

     

    2. The performance problem is because you are outputting a huge amount of markup to the browser each time the page is requested. this is not an efficient solution, which is why using an actual database, which is optimized to find and sort data, is how this is normally done.

     

    also, a scheme that writes an updated .html file every x amount of time would go away when using a database. you would use the current live data stored in the database on every page request.

     

    you are struggling to get this to work with 5000 items. a database solution will easily work with a million items in a table.

     

     

    As I said before, I'm not sure if the environment that I get the data from will be able to communicate nicely with a database like that. It doesn't like outputting data. And I have no idea how the webinvt.txt was created in the first place. I will have to see from my end what else can be done with the limited capabilities of the system. However, I believe that the main problem has been solved. Thanks all for your help! 

  2. 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..

     

     

    OK increasing that count seems to have worked. I can get the datatable to load correctly, however, there is still a problem. It generates another table first which then feeds into the datatable after a couple of seconds. The datatable should just load up without having to do that, I would think. This I'm guess is a problem with the way the PHP is set up. 

  3. 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>

  4. 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
    
                
    
  5. 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);
    
    
    ?>
    
  6.  

    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...

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

  8. 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. 

  9. 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();
    
    });
    
  10. 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... 

  11. 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>
            
  12. 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);
    
    
    ?>
  13. 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!

  14. 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. 

  15. 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> 
  16. $fp = fopen("webinvt.txt");
    while ($line = fgetcsv($fp, 1024)) {
        if (conditions met) {
            # use it
        }
        else {
            # don't use it
        }
    }
    fclose($fp);
    

     

     

    I got this to work: 

     

    <?php
    
    
    $file = fopen("webinvt.txt", "r");
    $items = array();
    
    
    while (!feof($file)) {
       $items[] = fgets($file);
    }
    
    
    fclose($file);
    
    
    var_dump($items);
    ?>

    but how do i selected which rows to show?

  17. Hello all, new to the forum. I have been struggling with a PHP problem for the past week and have turned to you as a last resort. I have everything set up mostly right, but there are specific features that I need from http://datatables.net/index that I would love to feature on my inventory page. What happens on my page, is that the whole csv contents show. But the rows do not hide as in the examples you can see on the datatables website. The search bar also does not appear. These are standard features nestled within the datatables.js code. So I am guess they disappear because of the way the PHP is set up to view the rows. These features are really important for the future functionality of my site as well! I have the PHP code as follows: 

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

    Furthermore, I have to include this piece of javascript inside the HTML variable.:

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

    Any help will be greatly appreciated! 

×
×
  • 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.