Go Back   HTMLCenter Web Development Forums > Web Design and Development > Programming and Scripting

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 07-23-2008, 11:18 AM
Registered User
 
Join Date: Jul 2004
Posts: 223
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"
Reply With Quote

  #2 (permalink)  
Old 07-23-2008, 08:05 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,396
PHP will exit a function as soon as it reaches a return statement. Therefore, any code you place after the "return" will never be executed. Put the echo statement before the return, and you'll be okay.
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote
  #3 (permalink)  
Old 07-24-2008, 06:40 PM
Registered User
 
Join Date: Jul 2004
Posts: 223
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(
"', ");
            } 
Reply With Quote
  #4 (permalink)  
Old 07-24-2008, 07:22 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,396
I hope I'm understanding this correctly. I'm assuming that you are saying that you want to store the entire "if" statement you mentioned in your second code block into a string variable. Is that correct?

If so, here is all you need to do:
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++;
        }
    } 
__________________
I hate Internet Explorer! Anyone with me?

Last edited by curtiss : 07-24-2008 at 07:26 PM.
Reply With Quote
  #5 (permalink)  
Old 07-24-2008, 07:37 PM
Registered User
 
Join Date: Jul 2004
Posts: 223
Quote:
Originally Posted by curtiss View Post
I hope I'm understanding this correctly. I'm assuming that you are saying that you want to store the entire "if" statement you mentioned in your second code block into a string variable. Is that correct?

If so, here is all you need to do:
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++;
        }
    } 
Why isn't it printing?
Reply With Quote
  #6 (permalink)  
Old 07-24-2008, 07:40 PM
Registered User
 
Join Date: Jul 2004
Posts: 223
I see what's going on.
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("\', ");
                }'
;
            }
            print(
$strLine[$line]);
            
//return $tdValues[$j];
            
$j++;
            
$line++;
        }
    } 
print($strLine[$line]); is printing the code on the page. But I need the result of the code inside the single quotes.
Reply With Quote
  #7 (permalink)  
Old 07-24-2008, 08:08 PM
Registered User
 
Join Date: Jul 2004
Posts: 223
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?
Reply With Quote
  #8 (permalink)  
Old 07-24-2008, 08:12 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,396
Gil - I don't think I can really help you much more unless I understand what it is you're ultimately trying to do.

The way your code is written, it's not really going to do anything at all. Unfortunately, I don't really understand what the goal is, so I can't begin to try to rewrite it to make it work for you.

Can you give me a short description of what it is you ultimately are trying to do?
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote
  #9 (permalink)  
Old 07-24-2008, 08:49 PM
Registered User
 
Join Date: Jul 2004
Posts: 223
Quote:
Originally Posted by curtiss View Post
Gil - I don't think I can really help you much more unless I understand what it is you're ultimately trying to do.

The way your code is written, it's not really going to do anything at all. Unfortunately, I don't really understand what the goal is, so I can't begin to try to rewrite it to make it work for you.

Can you give me a short description of what it is you ultimately are trying to do?
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 need $strLine[$line] to 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(
"', ");
            } 
I came across something close to what I wanted:
PHP: create_function - Manual
The example:
PHP Code:
<?php
$newfunc 
create_function('$a,$b''return "ln($a) + ln($b) = " . log($a * $b);');
echo 
"New anonymous function: $newfunc\n";
echo 
$newfunc(2M_E) . "\n";
// outputs
// New anonymous function: lambda_1
// ln(2) + ln(2.718281828459) = 1.6931471805599
?>
Is that all that you need to know? Or you want me to explain further?
Reply With Quote
  #10 (permalink)  
Old 07-24-2008, 10:50 PM
Registered User
 
Join Date: Jul 2004
Posts: 223
I almost succeeded into building my sql statement. But here is the result:
Quote:
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:
Quote:
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++;
        }
        
    }
    

Reply With Quote
  #11 (permalink)  
Old 07-27-2008, 07:14 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,396
Gil - That's just because you're performing the following action every time the loop runs through a cycle:
PHP Code:
print($strLine[$line]."<br />\n"); 
The print statement you have after setting the $sql variable each time is plenty.

In order to avoid the first empty statement, I would recommend changing this statement:
PHP Code:
if($k == 0){ 
to
PHP Code:
if($k == && !empty($k)){ 
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On