Web Analytics Made Easy -
StatCounter stopping a for loop while reading a excel file - CodingForum

Announcement

Collapse
No announcement yet.

stopping a for loop while reading a excel file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • stopping a for loop while reading a excel file

    hi all,

    This is trying to read an unknow amount of info from a excel file.

    i used a for loop to do this, but could not get it to stop.

    PHP Code:
    $over 1;

    for (
    $i=1;$over=1;){
    $excel_cell $Worksheet->Cells($i,1);
    $excel_cell->activate;
    $excel_result $excel_cell->value;
    print 
    "$excel_result\n";
    $i++;
    $excel_cell $Worksheet->Cells($i,1);
    $excel_cell->activate;
    $excel_result $excel_cell->value;
    if (
    $excel_result null){
        
    $over 0;}

    i thought if it picked up a blank cell value it would be null, but that does not stop the loop. i tried uusing "" and '' as well, but with no success.

    Thanks for all your help in advance

  • #2
    i don't understand the logic in your code so this is just a reply about detecting the Null/void/''.

    try
    PHP Code:
    if (strlen($excel_result) < 1){ 
        
    $over 0;}

    if you want to compare it to a value, then you need to use either == or === as comparison-operator. = is not a comparisonoperator --> it assigns a value to the variable.

    but realy, your reading should break on an feof('yourfile') or you should just use a file_get_contents() or so.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

    Comment


    • #3
      done!, it was the "==", thanks a lot.

      Comment


      • #4
        You could use break;
        Last edited by marek_mar; Oct 5, 2006, 02:52 PM.
        I'm not sure if this was any help, but I hope it didn't make you stupider.

        Experience is something you get just after you really need it.
        PHP Installation Guide Feedback welcome.

        Comment


        • #5
          Originally posted by marek_mar View Post
          Yopu could use break;
          yeah, that looping should be done completely different...
          Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

          Comment

          Working...
          X