for loops.....code breaks

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hemanth

    #1

    for loops.....code breaks

    Hello there,

    I'm trying to read an excel worksheet (with more than 5000 rows and 30
    columns) using PHP. I'm using the "excelreade r" script I found over the
    web - http://sourceforge.net/projects/phpexcelreader/.

    Seems to me, the script reads the values in all cells correctly and
    stores the total number of rows and columns existing in the worksheet
    (For example, in the excel file I'm using - total rows: 5375 and cols:
    37). The problem is when I try to print the values as a HTML table
    (using two for loops), the script prints only first 236 rows and stops
    execution. The following is the code snippet I use:

    for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++)
    {
    echo "<TR>";
    for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++)
    {
    echo "<TD>".$dat a->sheets[0]['cells'][$i][$j];
    }
    echo "<BR>";
    }

    I've also set the script execution time to 5-10 mins using
    "set_time_limit " function, but the script still ends after printing 236
    rows (takes less than a minute). I spot checked the cell values by
    printing values from 300 to 500, 5200 to 5375 etc. The values seems to
    okay and stored correctly in the arrays. From what I understood, the
    for loops doesn't execute completely and I don't understand why?

    I've also created a small test script to see if the loops work and the
    following code breaks...I don't see a output.

    <?php
    set_time_limit( 300);

    for ($i = 1; $i <= 5000; $i++)
    {
    for($j = 1; $j <= 40; $j++)
    {
    $data[$i][$j] = "mycell - $i$j"; //. ($i * $j);
    }
    }
    echo "PRINTING TABLE....<BR>";

    echo "<table border='1'>";
    for ($i = 1; $i <= 1000; $i++)
    {
    echo "<TR><TD>[$i]";
    for($j = 1; $j <= 20; $j++)
    {
    echo "<TD>". $data[$i][$j];
    }
    echo "<BR>";
    }
    echo "</table>";
    ?>

    Can anyone throw some light on it. Appreciate your help.


    TIA,
    Hemanth

    P.S: I'm using IE5.5, PHP4.1.2, Firefox1.0.4

  • Jeff North

    #2
    Re: for loops.....code breaks

    On 3 Nov 2005 16:26:33 -0800, in comp.lang.php "Hemanth"
    <hemanth.singam setty@gmail.com > wrote:
    [color=blue]
    >| Hello there,
    >|
    >| I'm trying to read an excel worksheet (with more than 5000 rows and 30
    >| columns) using PHP. I'm using the "excelreade r" script I found over the
    >| web - http://sourceforge.net/projects/phpexcelreader/.
    >|
    >| Seems to me, the script reads the values in all cells correctly and
    >| stores the total number of rows and columns existing in the worksheet
    >| (For example, in the excel file I'm using - total rows: 5375 and cols:
    >| 37). The problem is when I try to print the values as a HTML table
    >| (using two for loops), the script prints only first 236 rows and stops
    >| execution. The following is the code snippet I use:
    >|
    >| for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++)
    >| {
    >| echo "<TR>";
    >| for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++)
    >| {
    >| echo "<TD>".$dat a->sheets[0]['cells'][$i][$j];
    >| }
    >| echo "<BR>";
    >| }[/color]

    You might want to put a closing </td> and </tr> at the end of your
    statements. You could get away with this years ago but browsers are
    becoming more unforgiving (thank goodness).
    [color=blue]
    >| I've also set the script execution time to 5-10 mins using
    >| "set_time_limit " function, but the script still ends after printing 236
    >| rows (takes less than a minute). I spot checked the cell values by
    >| printing values from 300 to 500, 5200 to 5375 etc. The values seems to
    >| okay and stored correctly in the arrays. From what I understood, the
    >| for loops doesn't execute completely and I don't understand why?
    >|
    >| I've also created a small test script to see if the loops work and the
    >| following code breaks...I don't see a output.
    >|
    >| <?php
    >| set_time_limit( 300);
    >|
    >| for ($i = 1; $i <= 5000; $i++)
    >| {
    >| for($j = 1; $j <= 40; $j++)
    >| {
    >| $data[$i][$j] = "mycell - $i$j"; //. ($i * $j);
    >| }
    >| }
    >| echo "PRINTING TABLE....<BR>";
    >|
    >| echo "<table border='1'>";
    >| for ($i = 1; $i <= 1000; $i++)
    >| {
    >| echo "<TR><TD>[$i]";
    >| for($j = 1; $j <= 20; $j++)
    >| {
    >| echo "<TD>". $data[$i][$j];
    >| }
    >| echo "<BR>";
    >| }
    >| echo "</table>";
    >| ?>
    >|
    >| Can anyone throw some light on it. Appreciate your help.
    >|
    >|
    >| TIA,
    >| Hemanth
    >|
    >| P.S: I'm using IE5.5, PHP4.1.2, Firefox1.0.4[/color]
    ---------------------------------------------------------------
    jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
    ---------------------------------------------------------------

    Comment

    • Hemanth

      #3
      Re: for loops.....code breaks


      Jeff North wrote:[color=blue]
      > On 3 Nov 2005 16:26:33 -0800, in comp.lang.php "Hemanth"
      > <hemanth.singam setty@gmail.com > wrote:
      >[color=green]
      > >| Hello there,
      > >|
      > >| I'm trying to read an excel worksheet (with more than 5000 rows and 30
      > >| columns) using PHP. I'm using the "excelreade r" script I found over the
      > >| web - http://sourceforge.net/projects/phpexcelreader/.
      > >|
      > >| Seems to me, the script reads the values in all cells correctly and
      > >| stores the total number of rows and columns existing in the worksheet
      > >| (For example, in the excel file I'm using - total rows: 5375 and cols:
      > >| 37). The problem is when I try to print the values as a HTML table
      > >| (using two for loops), the script prints only first 236 rows and stops
      > >| execution. The following is the code snippet I use:
      > >|
      > >| for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++)
      > >| {
      > >| echo "<TR>";
      > >| for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++)
      > >| {
      > >| echo "<TD>".$dat a->sheets[0]['cells'][$i][$j];
      > >| }
      > >| echo "<BR>";
      > >| }[/color]
      >
      > You might want to put a closing </td> and </tr> at the end of your
      > statements. You could get away with this years ago but browsers are
      > becoming more unforgiving (thank goodness).
      >[/color]

      ......I don't see that as a problem. Anyway, I placed the closing tags
      but it didn't help.

      - Hemanth

      Comment

      • Jeff North

        #4
        Re: for loops.....code breaks

        On 4 Nov 2005 10:34:21 -0800, in comp.lang.php "Hemanth"
        <hemanth.singam setty@gmail.com > wrote:
        [color=blue]
        >|
        >| Jeff North wrote:
        >| > On 3 Nov 2005 16:26:33 -0800, in comp.lang.php "Hemanth"
        >| > <hemanth.singam setty@gmail.com > wrote:
        >| >
        >| > >| Hello there,
        >| > >|
        >| > >| I'm trying to read an excel worksheet (with more than 5000 rows and 30
        >| > >| columns) using PHP. I'm using the "excelreade r" script I found over the
        >| > >| web - http://sourceforge.net/projects/phpexcelreader/.
        >| > >|
        >| > >| Seems to me, the script reads the values in all cells correctly and
        >| > >| stores the total number of rows and columns existing in the worksheet
        >| > >| (For example, in the excel file I'm using - total rows: 5375 and cols:
        >| > >| 37). The problem is when I try to print the values as a HTML table
        >| > >| (using two for loops), the script prints only first 236 rows and stops
        >| > >| execution. The following is the code snippet I use:
        >| > >|
        >| > >| for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++)
        >| > >| {
        >| > >| echo "<TR>";
        >| > >| for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++)
        >| > >| {
        >| > >| echo "<TD>".$dat a->sheets[0]['cells'][$i][$j];
        >| > >| }
        >| > >| echo "<BR>";
        >| > >| }
        >| >
        >| > You might want to put a closing </td> and </tr> at the end of your
        >| > statements. You could get away with this years ago but browsers are
        >| > becoming more unforgiving (thank goodness).
        >| >
        >|
        >| .....I don't see that as a problem. Anyway, I placed the closing tags
        >| but it didn't help.[/color]

        OK, now put some echo statements in the read loop to see what is
        actually coming in and being processed.

        Also have a look at the spreadsheet row 236. Is there anything strange
        within that row that could be causing problems?
        ---------------------------------------------------------------
        jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
        ---------------------------------------------------------------

        Comment

        • Andy Hassall

          #5
          Re: for loops.....code breaks

          On Fri, 04 Nov 2005 05:38:28 GMT, Jeff North <jnorthau@yahoo .com.au> wrote:
          [color=blue]
          >You might want to put a closing </td> and </tr> at the end of your
          >statements. You could get away with this years ago but browsers are
          >becoming more unforgiving (thank goodness).[/color]

          It is good if they are becoming more unforgiving for real breaches of the
          standard (made-up elements, incorrect nesting, etc.), but missing </td> and
          </tr> is perfectly valid according to the HTML 4.01 standard.

          See http://www.w3.org/TR/html401/index/elements.html - <tr> and <td> have "O"
          denoting "Optional" in the close tag column.
          --
          Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
          http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

          Comment

          • Jeff North

            #6
            Re: for loops.....code breaks

            On Fri, 04 Nov 2005 20:58:35 +0000, in comp.lang.php Andy Hassall
            <andy@andyh.co. uk> wrote:
            [color=blue]
            >| On Fri, 04 Nov 2005 05:38:28 GMT, Jeff North <jnorthau@yahoo .com.au> wrote:
            >|
            >| >You might want to put a closing </td> and </tr> at the end of your
            >| >statements. You could get away with this years ago but browsers are
            >| >becoming more unforgiving (thank goodness).
            >|
            >| It is good if they are becoming more unforgiving for real breaches of the
            >| standard (made-up elements, incorrect nesting, etc.), but missing </td> and
            >| </tr> is perfectly valid according to the HTML 4.01 standard.
            >|
            >| See http://www.w3.org/TR/html401/index/elements.html - <tr> and <td> have "O"
            >| denoting "Optional" in the close tag column.[/color]

            True, but I always set my headings to use XHTML then I know *all* tags
            need to be closed :-)
            ---------------------------------------------------------------
            jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
            ---------------------------------------------------------------

            Comment

            Working...