#1 (permalink)  
Old 08-06-2008, 12:59 PM
Registered User
 
Join Date: Jul 2004
Posts: 249
Array not written properly

I have an array resulted from a function but can't figure out how to set it properly:
Code:
Array
(
    [0] => 
    [1] => <br />

    [2] => <span class="goToBookChapter" style="font-weight: bold;">Genesis 29:2</span><br />

    [3] => <br />

    [4] => And he <span class="" id="" style="color:MediumTurquoise; font-weight:bold;">looked</span>, and <span class="" id="" style="color:DarkRed; font-weight:bold;">behold</span> a well in the field, and, lo, there were three <span class="" id="" style="color:Teal; font-weight:bold;">flock</span>s of sheep lying by it; for out of that well they watered the <span class="" id="" style="color:Teal; font-weight:bold;">flock</span>s: and a <span class="" id="" style="color:; font-weight:bold;">great</span> stone was upon the well's mouth.<br />

    [5] => <br />

    [6] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 2:16</span><br />

    [7] => <br />

    [8] => Now the <span class="" id="" style="color:green; font-weight:bold;">priest</span> of <span class="" id="" style="color:PaleGreen; font-weight:bold;">Midian</span> had seven daughters: and they came and drew water, and filled the troughs to water their <span class="" id="" style="color:Magenta; font-weight:bold;">father</span>'s <span class="" id="" style="color:Teal; font-weight:bold;">flock</span>.<br />

    [9] => <br />

    [10] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 3:1</span><br />

    [11] => <br />

    [12] => Now <span class="" id="" style="color:red; font-weight:bold;">Moses</span> kept the <span class="" id="" style="color:Teal; font-weight:bold;">flock</span> of <span class="" id="" style="color:blue; font-weight:bold;">Jethro</span> his <span class="" id="" style="color:Magenta; font-weight:bold;">father</span> in law, the <span class="" id="" style="color:green; font-weight:bold;">priest</span> of <span class="" id="" style="color:PaleGreen; font-weight:bold;">Midian</span>: and he led the <span class="" id="" style="color:Teal; font-weight:bold;">flock</span> to the <span class="" id="" style="color:orange; font-weight:bold;">backside</span> of the <span class="" id="" style="color:purple; font-weight:bold;">desert</span>, and came to the <span class="" id="" style="color:Pink; font-weight:bold;">mountain</span> of God, even to <span class="" id="" style="color:YellowGreen; font-weight:bold;">Horeb</span>.<br />

    [13] => <br />

    [14] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 3:2</span><br />

    [15] => <br />

    [16] => And the <span class="" id="" style="color:Sienna; font-weight:bold;">angel</span> of the LORD <span class="" id="" style="color:aqua; font-weight:bold;">appeared</span> unto him in a <span class="" id="" style="color:Gray; font-weight:bold;">flame</span> of fire out of the <span class="" id="" style="color:LightBlue; font-weight:bold;">midst</span> of a bush: and he <span class="" id="" style="color:MediumTurquoise; font-weight:bold;">looked</span>, and, <span class="" id="" style="color:DarkRed; font-weight:bold;">behold</span>, the bush <span class="" id="" style="color:; font-weight:bold;">burned</span> with fire, and the bush was not <span class="" id="" style="color:; font-weight:bold;">consumed</span>.<br />

    [17] => <br />

    [18] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 3:3</span><br />

    [19] => <br />

    [20] => And <span class="" id="" style="color:red; font-weight:bold;">Moses</span> said, I will now turn <span class="" id="" style="color:; font-weight:bold;">aside</span>, and see this <span class="" id="" style="color:; font-weight:bold;">great</span> <span class="" id="" style="color:; font-weight:bold;">sight</span>, why the bush is not <span class="" id="" style="color:; font-weight:bold;">burnt</span>.<br />

    [21] => <br />

    [22] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 17:6</span><br />

    [23] => <br />

    [24] => <span class="" id="" style="color:DarkRed; font-weight:bold;">Behold</span>, I will stand before thee there upon the rock in <span class="" id="" style="color:YellowGreen; font-weight:bold;">Horeb</span>; and thou shalt smite the rock, and there shall come water out of it, that the people may drink. And <span class="" id="" style="color:red; font-weight:bold;">Moses</span> did so in the <span class="" id="" style="color:; font-weight:bold;">sight</span> of the elders of Israel.<br />

    [25] => <br />

    [26] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 18:1</span><br />

    [27] => <br />

    [28] => When <span class="" id="" style="color:blue; font-weight:bold;">Jethro</span>, the <span class="" id="" style="color:green; font-weight:bold;">priest</span> of <span class="" id="" style="color:PaleGreen; font-weight:bold;">Midian</span>, <span class="" id="" style="color:red; font-weight:bold;">Moses</span>' <span class="" id="" style="color:Magenta; font-weight:bold;">father</span> in law, heard of all that God had done for <span class="" id="" style="color:red; font-weight:bold;">Moses</span>, and for Israel his people, and that the LORD had brought Israel out of Egypt;<br />

    [29] => <br />

    [30] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 18:12</span><br />

    [31] => <br />

    [32] => And <span class="" id="" style="color:blue; font-weight:bold;">Jethro</span>, <span class="" id="" style="color:red; font-weight:bold;">Moses</span>' <span class="" id="" style="color:Magenta; font-weight:bold;">father</span> in law, took a <span class="" id="" style="color:; font-weight:bold;">burnt</span> offering and sacrifices for God: and Aaron came, and all the elders of Israel, to eat bread with <span class="" id="" style="color:red; font-weight:bold;">Moses</span>' <span class="" id="" style="color:Magenta; font-weight:bold;">father</span> in law before God.<br />

)
The function is:
PHP Code:
function getQuery($bigWords){
...
        
$theresult = array();
        
$theresult[] = "";
        
//$theresult[] = $query;
        
$result mysql_query($query);

    while(
$row mysql_fetch_assoc($result)){
        
$theresult[] .= "<br />\n";
        
$theresult[] .= "<span class=\"goToBookChapter\" style=\"font-weight: bold;\">".$row['book_title']." ".$row['chapter'].":".$row['verse']."</span><br />\n";
    
        
$strText $row['text_data'];
        
$COLORS = array('red','Teal','blue','Magenta','green','PaleGreen','orange','purple','Pink','YellowGreen','Sienna','aqua','Gray','LightBlue','MediumTurquoise','DarkRed');
        for(
$m=0$m count($bigWords); $m++){
            
$strText preg_replace("/(".$bigWords[$m].")/i""<span class=\"\" id=\"\" style=\"color:".$COLORS[$m]."; font-weight:bold;\">$1</span>"$strText);
            }
        
$theresult[] .= "<br />\n";
        
$theresult[] .= $strText."<br />\n";
        }
        return 
$theresult;
        echo 
"<br /><br />".$query."<br />";
}
        
        echo 
"Words searched for:<br />\n";
        
$bigWords array_values($bigWords);
        
        
        
//to make $k start the $COLORS from 0
        
$k 0;
        for (
$j=0$j count($bigWords); $j++){
                if(
$bigWords[$j]!=""){
                    echo 
"<span style='font-weight: bold; color: ".$COLORS[$k].";'>".$bigWords[$j]."</span>\n";
                    if(
$j!=count($bigWords)-1){
                        echo 
" + ";
                        }else{
                        
//removes the OR from the last line and replaces with the following
                        //for results of words > 3
                        
echo ".<br />\n";
                        }
                    
$k++;    
                }
        }
    
print_r(getQuery($bigWords)); 
It should be:
Code:
Array
(
    [0] =><br /><span class="goToBookChapter" style="font-weight: bold;">Genesis 29:2</span><br /><br />And he <span class="" id="" style="color:MediumTurquoise; font-weight:bold;">looked</span>, and <span class="" id="" style="color:DarkRed; font-weight:bold;">behold</span> a well in the field, and, lo, there were three <span class="" id="" style="color:Teal; font-weight:bold;">flock</span>s of sheep lying by it; for out of that well they watered the <span class="" id="" style="color:Teal; font-weight:bold;">flock</span>s: and a <span class="" id="" style="color:; font-weight:bold;">great</span> stone was upon the well's mouth.<br />

    [1] => <br /><span class="goToBookChapter" style="font-weight: bold;">Exodus 2:16</span><br /><br />Now the <span class="" id="" style="color:green; font-weight:bold;">priest</span> of <span class="" id="" style="color:PaleGreen; font-weight:bold;">Midian</span> had seven daughters: and they came and drew water, and filled the troughs to water their <span class="" id="" style="color:Magenta; font-weight:bold;">father</span>'s <span class="" id="" style="color:Teal; font-weight:bold;">flock</span>.<br /><br />

    [2] => <span class="goToBookChapter" style="font-weight: bold;">Exodus 3:1</span><br /><br />Now <span class="" id="" style="color:red; font-weight:bold;">Moses</span> kept the <span class="" id="" style="color:Teal; font-weight:bold;">flock</span> of <span class="" id="" style="color:blue; font-weight:bold;">Jethro</span> his <span class="" id="" style="color:Magenta; font-weight:bold;">father</span> in law, the <span class="" id="" style="color:green; font-weight:bold;">priest</span> of <span class="" id="" style="color:PaleGreen; font-weight:bold;">Midian</span>: and he led the <span class="" id="" style="color:Teal; font-weight:bold;">flock</span> to the <span class="" id="" style="color:orange; font-weight:bold;">backside</span> of the <span class="" id="" style="color:purple; font-weight:bold;">desert</span>, and came to the <span class="" id="" style="color:Pink; font-weight:bold;">mountain</span> of God, even to <span class="" id="" style="color:YellowGreen; font-weight:bold;">Horeb</span>.<br />
}
__________________
Gilgal's website:
Wheel Of God
Now easy to post scripture verses!
Portfolio
Reply With Quote

  #2 (permalink)  
Old 08-06-2008, 01:16 PM
Registered User
 
Join Date: Jul 2004
Posts: 249
Ok ok. By eliminating .= and joining strings together I managed to fix some parts of the array. However there is the first part which causes [0] to show blank. How do I get around $theresult[] = ""; not showing in [0]=>?
The reason for avoiding is that I have a pagination code where the first page will show one less because of this:
PHP Code:
    function getQuery($bigWords){

...
        
$theresult = array();
        
$theresult[] = "";
        
//$theresult[] = $query;
        
$result mysql_query($query);

    while(
$row mysql_fetch_assoc($result)){
        
$strText $row['text_data'];
        
$COLORS = array('red','Teal','blue','Magenta','green','PaleGreen','orange','purple','Pink','YellowGreen','Sienna','aqua','Gray','LightBlue','MediumTurquoise','DarkRed');
        for(
$m=0$m count($bigWords); $m++){
            
$strText preg_replace("/(".$bigWords[$m].")/i""<span class=\"\" id=\"\" style=\"color:".$COLORS[$m]."; font-weight:bold;\">$1</span>"$strText);
            }
        
$theresult[] .= "<br />\n<span class=\"goToBookChapter\" style=\"font-weight: bold;\">".$row['book_title']." ".$row['chapter'].":".$row['verse']."</span><br />\n".$strText;
        }
        return 
$theresult;
        echo 
"<br /><br />".$query."<br />";

__________________
Gilgal's website:
Wheel Of God
Now easy to post scripture verses!
Portfolio
Reply With Quote
  #3 (permalink)  
Old 08-06-2008, 01:26 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,445
Delete the following line of code:
PHP Code:
        $theresult[] = ""
Also, the following line of code should not have a dot in front of the equal sign:
PHP Code:
        $theresult[] .= "<br />\n<span class=\"goToBookChapter\" style=\"font-weight: bold;\">".$row['book_title']." ".$row['chapter'].":".$row['verse']."</span><br />\n".$strText
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote
  #4 (permalink)  
Old 08-06-2008, 01:51 PM
Registered User
 
Join Date: Jul 2004
Posts: 249
Hip Hip Array!
__________________
Gilgal's website:
Wheel Of God
Now easy to post scripture verses!
Portfolio
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
php call a function in array() gilgalbiblewhee Programming and Scripting 0 07-06-2008 01:43 PM
array and split warning in php gilgalbiblewhee Programming and Scripting 2 11-07-2007 02:19 PM
javascript: html page array with an iframe Epsilon Programming and Scripting 4 05-10-2007 06:50 PM
Newb needs help with parsing an array into html output GregGaub Programming and Scripting 1 03-20-2005 06:39 PM


All times are GMT -5. The time now is 07:44 AM.

 
Bitrix
Clicky Web Analytics
CloudContacts
Maxtango


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter