Results 1 to 11 of 11

Thread: function not printing

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    function not printing

    I don't know if I missed something. The function is not printing at all.
    PHP Code:
    $contents_of_page file_get_contents('../bible1.html');

    preg_match_all("#<td.*>(.+)</td#Ui"$contents_of_page$tdInnerHTML);
    $totaltds count($tdInnerHTML[1]);
    print_r($tdInnerHTML[1]);//prints all TD contents 

    /********************************************************************************/
    function recValues(){
        
    $tdValues = array();
        
    $tdValues "";
        for(
    $j 0$j $totaltds$j++){
            if(
    $j 10 != 0){
                
    $tdValues .= "'".$tdInnerHTML[1][$j];
                if(
    $j 9){
                    
    $tdValues .= "', ";
                    }else{
                    
    $tdValues .= "'";
                    }
                }
            }
        return 
    $tdValues;
        }
        echo 
    "<span style='font-weight: bold;'>hi".recValues()."hi</span><br />\n"
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: function not printing

    That's because you use the return statement before the echo. I.e: the function exits before it can print anything and the echo statement is never executed.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    Re: function not printing

    Ok so I moved some things in the function.
    But another problem appears.The last $tdValues .= "'".$tdInnerHTML[1][$j]; shouldn't have ,' that follows it. I'm avoiding the multiples of 10 if($j % 10 != 0){
    PHP Code:
    function recValues(){
    $contents_of_page file_get_contents('../bible1.html');
    preg_match_all("#<td.*>(.+)</td#Ui"$contents_of_page$tdInnerHTML);
    $totaltds count($tdInnerHTML[1]);
    print_r($tdInnerHTML[1]);//prints all TD contents 
        
    $tdValues = array();
        
    $tdValues "";
        for(
    $j 0$j $totaltds$j++){
            if(
    $j 10 != 0){
                
    $tdValues .= "'".$tdInnerHTML[1][$j];
                
    $tdValues .= "', ";
                if(
    $j 10 != 9){
                    
    $tdValues .= "'";
                    
    $tdValues .= "<br />";
                    }
                }
            }
        return 
    $tdValues;
        }
        echo 
    "<span style='font-weight: bold;'>".recValues()."</span><br />\n"
    So it's this part of the code that has to be fixed. I want to insert at every (multiple of 10) + 9. In other words 19, 29, 39...
    PHP Code:
                if($j 10 != 9){
                    
    $tdValues .= "'";
                    
    $tdValues .= "<br />";
                    }
                } 
    Compare bible texts (and other tools):
    TheWheelofGod

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: function not printing

    Neither your code or you explanation make much sense. Please indent your code; I have done this for you below, it makes it easier for everyone and will mean your problem will get solved quicker.

    Have a look at the explanations below:
    PHP Code:
    <?php
    function recValues()
    {
        
    $contents_of_page file_get_contents('../bible1.html');
        
    preg_match_all("#<td.*>(.+)</td#Ui"$contents_of_page$tdInnerHTML);
        
    $totaltds count($tdInnerHTML[1]);
        
    print_r($tdInnerHTML[1]); //prints all TD contents
        
        
    $tdValues = array(); /*** this line is pointless, you reset
                the value of the same variable on the line below ***/
        
            
    $tdValues "";
        
        for(
    $j 0$j $totaltds$j++){
            if(
    $j 10 != 0) {
                
    /*** $j is >= 1 and <= 9 ***/

                        
    $tdValues .= "'".$tdInnerHTML[1][$j];
                        
    $tdValues .= "', ";
                
                if(
    $j 10 != 9){ /*** isn't 0 + 9 == 9 ??? ***/
                    /*** $j must be >= 1 and <= 8 */
                            
    $tdValues .= "'";
                            
    $tdValues .= "<br />";
                        }
                    }
            }
            
        return 
    $tdValues;
    }

    echo 
    "<span style='font-weight: bold;'>".recValues()."</span><br />\n"

    ?>
    I added the indentation too. The first if statement in your look will get executed for the values of $j (1,2,3,4,5,6,7,8,9,11,12,13,14,15,6,17,18,19,21 ....). The second if statement will get executed for these values of $j (1,2,3,4,5,6,7,8,11,12,13,14,15,16,17,18,21).
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    Re: function not printing

    Quote Originally Posted by visualAd
    Neither your code or you explanation make much sense. Please indent your code; I have done this for you below, it makes it easier for everyone and will mean your problem will get solved quicker.

    Have a look at the explanations below:
    PHP Code:
    <?php
    function recValues()
    {
        
    $contents_of_page file_get_contents('../bible1.html');
        
    preg_match_all("#<td.*>(.+)</td#Ui"$contents_of_page$tdInnerHTML);
        
    $totaltds count($tdInnerHTML[1]);
        
    print_r($tdInnerHTML[1]); //prints all TD contents
        
        
    $tdValues = array(); /*** this line is pointless, you reset
                the value of the same variable on the line below ***/
        
            
    $tdValues "";
        
        for(
    $j 0$j $totaltds$j++){
            if(
    $j 10 != 0) {
                
    /*** $j is >= 1 and <= 9 ***/

                        
    $tdValues .= "'".$tdInnerHTML[1][$j];
                        
    $tdValues .= "', ";
                
                if(
    $j 10 != 9){ /*** isn't 0 + 9 == 9 ??? ***/
                    /*** $j must be >= 1 and <= 8 */
                            
    $tdValues .= "'";
                            
    $tdValues .= "<br />";
                        }
                    }
            }
            
        return 
    $tdValues;
    }

    echo 
    "<span style='font-weight: bold;'>".recValues()."</span><br />\n"

    ?>
    I added the indentation too. The first if statement in your look will get executed for the values of $j (1,2,3,4,5,6,7,8,9,11,12,13,14,15,6,17,18,19,21 ....). The second if statement will get executed for these values of $j (1,2,3,4,5,6,7,8,11,12,13,14,15,16,17,18,21).
    I did the following changes and it worked:
    PHP Code:
    function recValues(){
        
    $contents_of_page file_get_contents('../bible1.html');
        
    preg_match_all("#<td.*>(.+)</td#Ui"$contents_of_page$tdInnerHTML);
        
    $totaltds count($tdInnerHTML[1]);
        
    print_r($tdInnerHTML[1]);//prints all TD contents 
        
    $tdValues = array();
        
    $tdValues "";
        for(
    $j 0$j $totaltds$j++){
            if(
    $j 10 != 0){
                
    $tdValues .= "'".$tdInnerHTML[1][$j];
                if(
    $j 10 == 9){
                    
    $tdValues .= "'";
                    
    $tdValues .= "<br />";
                    }else{
                    
    $tdValues .= "', ";
                    }
                }
            }
        return 
    $tdValues;
        }
    echo 
    "<span style='font-weight: bold;'>".recValues()."</span><br />\n"
    I get the following result:
    '1', '1', 'gn', 'Genesis', '1', '1', '1', '1', 'In the beginning God created the heaven and the earth.'
    '1', '1', 'gn', 'Genesis', '1', '1', '2', '2', 'And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.'
    '1', '1', 'gn', 'Genesis', '1', '1', '3', '3', 'And God said, Let there be light: and there was light.'
    '1', '1', 'gn', 'Genesis', '1', '1', '4', '4', 'And God saw the light, that it was good: and God divided the light from the darkness.'
    ...
    But what I want to add is $k being equal to each line so that:
    PHP Code:
    echo "<span style='font-weight: bold;'>".recValues()."</span><br />\n"
    will not give the whole chunk of results. I'm not sure how I should manage to do that.
    Compare bible texts (and other tools):
    TheWheelofGod

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: function not printing

    You are going to have to be move specific, I don't understand what you mean.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    Re: function not printing

    Quote Originally Posted by visualAd
    You are going to have to be move specific, I don't understand what you mean.
    I want to create an array of $tdValues:
    PHP Code:
    $tdValues[0]
    $tdValues[1]
    $tdValues[2]
    ... 
    each $tdValues[$k] should have one line:
    '1', '1', 'gn', 'Genesis', '1', '1', '1', '1', 'In the beginning God created the heaven and the earth.'
    Because later on I have:
    PHP Code:
    for($k=0$k $totaltds$k++)
        
    $sql "INSERT INTO bible (".fields().") VALUES (".recValues().")";
        echo 
    $sql."<br />\n";

    There is recValues(). $tdValues[$k] needs to somehow replace that.
    Compare bible texts (and other tools):
    TheWheelofGod

  8. #8
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: function not printing

    Just declare $tdValues as an array. $tdValues = array(); And instead of using the string concatenation operator .= to add to it, use the array append operator [].

    PHP Code:
        for($j 0$j $totaltds$j++){
            
    $line'';
      
            
    /* build line data here */
            
    $tdValues[] = $line// add a new element to the array.
        

    P.s. are you taking this data from another site? If so, then please ensure that you have the permission of the site owner to copy their data. Otherwise you are breaking copyright law.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    Re: function not printing

    Quote Originally Posted by visualAd
    Just declare $tdValues as an array. $tdValues = array(); And instead of using the string concatenation operator .= to add to it, use the array append operator [].

    PHP Code:
        for($j 0$j $totaltds$j++){
            
    $line'';
      
            
    /* build line data here */
            
    $tdValues[] = $line// add a new element to the array.
        

    P.s. are you taking this data from another site? If so, then please ensure that you have the permission of the site owner to copy their data. Otherwise you are breaking copyright law.
    No I'm not. What happened was that I accidentally erased my db table. Fortunately I had a copy of the table in HTML. So I'm trying to reconvert it to a db table.

    Another problem was that I don't know how to upload a db table to an online server and connect to it. But I know how to connect to a created db on the online server. So I need this technique in both cases. I'm almost done with this.

    I find that the solution you gave is getting complicated. This means I have to do a lot more reading than I can bear.

    I decided to rework the function from scratch. THis is what I came up with:
    PHP Code:
    function recValues(){
        
    $contents_of_page file_get_contents('../bible1.html');
        
    preg_match_all("#<td.*>(.+)</td#Ui"$contents_of_page$tdInnerHTML);
        
    $totaltds count($tdInnerHTML[1]);
        
    $line 0;
        
    $strLine = array();
        for(
    $k=0$k $totaltds$k++){
            if(
    $k 10 == 0){
                print(
    "line ");
                
    $strLine[$line] = 
                }
            if(
    $k 10 != 0){
                
    $j 0;
                
    $tdValues = array();
                
    $tdValues[$j] = $tdInnerHTML[1][$k];
                print(
    "'");
                print(
    "<span style='font-weight: bold; color: red'>".$tdValues[$j]."</span>");
                
    //print($tdInnerHTML[1][$k]);
                
    if($k 10 == 9){
                    print(
    "'<br />\n");
                }else{
                    print(
    "', ");
                }
                
    //return $tdValues[$j];
                
    $j++;
                
    $line++;
            }
        } 
    But I'm stuck. I need $strLine[$line] = to be equal to all this:
    PHP Code:
    if($k 10 != 0){
                
    $j 0;
                
    $tdValues = array();
                
    $tdValues[$j] = $tdInnerHTML[1][$k];
                print(
    "'");
                print(
    "<span style='font-weight: bold; color: red'>".$tdValues[$j]."</span>");
                
    //print($tdInnerHTML[1][$k]);
                
    if($k 10 == 9){
                    print(
    "'<br />\n");
                }else{
                    print(
    "', ");
                } 
    Compare bible texts (and other tools):
    TheWheelofGod

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    Re: function not printing

    How about making $strLine[$line] equal to a function which would have:
    PHP Code:
    if($k 10 != 0){
                
    $j 0;
                
    $tdValues = array();
                
    $tdValues[$j] = $tdInnerHTML[1][$k];
                print(
    "'");
                print(
    "<span style='font-weight: bold; color: red'>".$tdValues[$j]."</span>");
                
    //print($tdInnerHTML[1][$k]);
                
    if($k 10 == 9){
                    print(
    "'<br />\n");
                }else{
                    print(
    "', ");
                } 
    How does that work?
    Compare bible texts (and other tools):
    TheWheelofGod

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    Re: function not printing

    I almost succeeded into building my sql statement. But here is the result:
    line
    0 INSERT INTO bible (book, book_spoke, recordType, book_title, chapter, chapter_spoke, verse, verse_spoke, text_data) VALUES ()
    '1',
    '1', '1',
    '1', '1', 'gn',
    '1', '1', 'gn', 'Genesis',
    '1', '1', 'gn', 'Genesis', '1',
    '1', '1', 'gn', 'Genesis', '1', '1',
    '1', '1', 'gn', 'Genesis', '1', '1', '1',
    '1', '1', 'gn', 'Genesis', '1', '1', '1', '1',
    '1', '1', 'gn', 'Genesis', '1', '1', '1', '1', 'In the beginning God created the heaven and the earth.'
    9 INSERT INTO bible (book, book_spoke, recordType, book_title, chapter, chapter_spoke, verse, verse_spoke, text_data) VALUES ('1', '1', 'gn', 'Genesis', '1', '1', '1', '1', 'In the beginning God created the heaven and the earth.')
    line
    '1',
    '1', '1',
    '1', '1', 'gn',
    '1', '1', 'gn', 'Genesis',
    '1', '1', 'gn', 'Genesis', '1',
    '1', '1', 'gn', 'Genesis', '1', '1',
    '1', '1', 'gn', 'Genesis', '1', '1', '2',
    '1', '1', 'gn', 'Genesis', '1', '1', '2', '2',
    18 INSERT INTO bible (book, book_spoke, recordType, book_title, chapter, chapter_spoke, verse, verse_spoke, text_data) VALUES ('1', '1', 'gn', 'Genesis', '1', '1', '2', '2', )
    'And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.'
    line
    '1',
    '1', '1',
    '1', '1', 'gn',
    '1', '1', 'gn', 'Genesis',
    '1', '1', 'gn', 'Genesis', '1',
    '1', '1', 'gn', 'Genesis', '1', '1',
    '1', '1', 'gn', 'Genesis', '1', '1', '3',
    27 INSERT INTO bible (book, book_spoke, recordType, book_title, chapter, chapter_spoke, verse, verse_spoke, text_data) VALUES ('1', '1', 'gn', 'Genesis', '1', '1', '3', )
    '3',
    '3', 'And God said, Let there be light: and there was light.'
    As you see there is a repetition. Instead it should be:
    line

    9 INSERT INTO bible (book, book_spoke, recordType, book_title, chapter, chapter_spoke, verse, verse_spoke, text_data) VALUES ('1', '1', 'gn', 'Genesis', '1', '1', '1', '1', 'In the beginning God created the heaven and the earth.')
    line

    27 INSERT INTO bible (book, book_spoke, recordType, book_title, chapter, chapter_spoke, verse, verse_spoke, text_data) VALUES ('1', '1', 'gn', 'Genesis', '1', '1', '1', '1', 'And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.')
    line

    36 INSERT INTO bible (book, book_spoke, recordType, book_title, chapter, chapter_spoke, verse, verse_spoke, text_data) VALUES ('1', '1', 'gn', 'Genesis', '1', '1', '3', '3',
    'And God said, Let there be light: and there was light.')
    PHP Code:
    function recValues(){
        
    $contents_of_page file_get_contents('../bible1.html');
        
    preg_match_all("#<td.*>(.+)</td#Ui"$contents_of_page$tdInnerHTML);
        
    $totaltds count($tdInnerHTML[1]);
        
    $line 0;
        
    $strLine = array();
        for(
    $k=0$k $totaltds$k++){
            if(
    $k 10 == 0){
                print(
    "line ");
                
    $strLine[$line] = "";
            }
            if(
    $k 10 != 0){
                
    $j 0;
                
    $tdValues = array();
                
    $tdValues[$j] = $tdInnerHTML[1][$k];
                
    $strLine[$line] .= "'";
                
    //print("'");
                
    $strLine[$line] .= $tdValues[$j];
                
    //print("<span style='font-weight: bold; color: red'>".$tdValues[$j]."</span>");
                //print($tdInnerHTML[1][$k]);
                
    if($k 10 == 9){
                    
    $strLine[$line] .= "'";
                    
    //print("'<br />\n");
                
    }else{
                    
    $strLine[$line] .= "', ";
                    
    //print("', ");
                
    }
            }
            
            print(
    $strLine[$line]."<br />\n");
            
    //return $strLine[$line];
            
    $j++;
            if(
    $k == 0){
                
                
    $sql "INSERT INTO bible (".fields().") VALUES (".$strLine[$line].")";
                print(
    "<span style='color: red;'>".$k." ".$sql."</span><br />\n");
                
    $line++;
            }
            
        }
        

    Compare bible texts (and other tools):
    TheWheelofGod

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width