Function not going through the 2nd part of the array

the print_r of the array is written on top. But the sql and result shows the 1st part. The result shows twice the same result:

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [0] => altar
                    [1] => RGBA(10, 0, 0, 0.2)
                )

            [1] => Array
                (
                    [0] => offer
                    [1] => RGBA(100, 0, 0, 0.4)
                )

            [2] => Array
                (
                    [0] => burn
                    [1] => RGBA(100, 0, 0, 0.8)
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [0] => turn
                    [1] => RGBA(20, 0, 0, 0.4)
                )

            [1] => Array
                (
                    [0] => unto
                    [1] => RGBA(100, 0, 0, 0.6)
                )

        )

)
<h3>1Kings 8  <img src="images/chain_small.gif" alt="linked to">  Genesis 8</h3><br>
SELECT * FROM bible WHERE (book = '11' AND chapter= '8') AND (text_data LIKE '%altar%' OR text_data LIKE '%offer%' OR text_data LIKE '%burn%') ORDER BY id ASC<br>
SELECT * FROM bible WHERE (book = '1' AND chapter= '8') AND (text_data LIKE '%altar%' OR text_data LIKE '%offer%' OR text_data LIKE '%burn%') ORDER BY id ASC<br>
CREATE TABLE IF NOT EXISTS 1kings8_and_genesis8
		(1ki8_and_gen8_ID int(5) NOT NULL AUTO_INCREMENT PRIMARY KEY,
		date_time DATETIME,
		postorder INT(3),
		spoke INT(3),
		comments varchar(1000),
		joinids varchar(50),
		words varchar(120),
		color varchar(30)
		)<br><br><br>
<h4>Altar, Offer and Burn</h4><p></p><p class="BVerse"><span class="snavlink"><a href="http://www.blueletterbible.org/Bible.cfm?b=1ki&amp;c=8&amp;t=KJV" target="_blank">1Kings 8</a></span> - <span class="snavlink" style="font-size: 14px; font-weight: bold;"><a href="http://www.blueletterbible.org/assets/flash/mp3bibleplayer.cfm?b=11&amp;c=8&amp;t=KJV" target="_blank">Listen</a></span><br>
<span style="font-size: smaller; font-weight: bold; vertical-align: text-top;">22</span> And Solomon stood before the <span class="kw" id="" style="color: RGBA(10, 0, 0, 0.2); ">altar</span> of the LORD in the presence of all the congregation of Israel, and spread forth his hands toward heaven:<br>
<span style="font-size: smaller; font-weight: bold; vertical-align: text-top;">31</span> If any man trespass against his neighbor, and an oath be laid upon him to cause him to swear, and the oath come before thine <span class="kw" id="" style="color: RGBA(10, 0, 0, 0.2); ">altar</span> in this house:<br>
<span style="font-size: smaller; font-weight: bold; vertical-align: text-top;">54</span> And it was so, that when Solomon had made an end of praying all this prayer and supplication unto the LORD, he arose from before the <span class="kw" id="" style="color: RGBA(10, 0, 0, 0.2); ">altar</span> of the LORD, from kneeling on his knees with his hands spread up to heaven.<br>
<span style="font-size: smaller; font-weight: bold; vertical-align: text-top;">62</span> And the king, and all Israel with him, <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ed sacrifice before the LORD.<br>
<span style="font-size: smaller; font-weight: bold; vertical-align: text-top;">63</span> And Solomon <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ed a sacrifice of peace <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings, which he <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ed unto the LORD, two and twenty thousand oxen, and an hundred and twenty thousand sheep. So the king and all the children of Israel dedicated the house of the LORD.<br>
<span style="font-size: smaller; font-weight: bold; vertical-align: text-top;">64</span> The same day did the king hallow the middle of the court that was before the house of the LORD: for there he <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ed <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.8); ">burn</span>t <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings, and meat <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings, and the fat of the peace <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings: because the brazen <span class="kw" id="" style="color: RGBA(10, 0, 0, 0.2); ">altar</span> that was before the LORD was too little to receive the <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.8); ">burn</span>t <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings, and meat <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings, and the fat of the peace <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings.<br>
<br><br><br><span style="font-size: 14px; font-weight: bold;"><a href="http://www.blueletterbible.org/Bible.cfm?b=gen&amp;c=8&amp;t=KJV" target="_blank">Genesis 8</a></span> - <span style="font-size: 14px; font-weight: bold;"><a href="http://www.blueletterbible.org/assets/flash/mp3bibleplayer.cfm?b=1&amp;c=8&amp;t=KJV" target="_blank">Listen</a></span><br>
<span style="font-size: smaller; font-weight: bold; vertical-align: text-top;">20</span> And Noah builded an <span class="kw" id="" style="color: RGBA(10, 0, 0, 0.2); ">altar</span> unto the LORD; and took of every clean beast, and of every clean fowl, and <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ed <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.8); ">burn</span>t <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings on the <span class="kw" id="" style="color: RGBA(10, 0, 0, 0.2); ">altar</span>.<br>
</p><br><br><br><h4>Altar, Offer and Burn</h4><p></p><p class="BVerse"><span class="snavlink"><a href="http://www.blueletterbible.org/Bible.cfm?b=1ki&amp;c=8&amp;t=KJV" target="_blank">1Kings 8</a></span> - <span class="snavlink" style="font-size: 14px; font-weight: bold;"><a href="http://www.blueletterbible.org/assets/flash/mp3bibleplayer.cfm?b=11&amp;c=8&amp;t=KJV" target="_blank">Listen</a></span><br>
<span style="font-size: smaller; font-weight: bold; vertical-align: text-top;">22</span> And Solomon stood before the <span class="kw" id="" style="color: RGBA(10, 0, 0, 0.2); ">altar</span> of the LORD in the presence of all the congregation of Israel, and spread forth his hands toward heaven:<br>
<span style="font-size: smaller; font-weight: bold; vertical-align: text-top;">31</span> If any man trespass against his neighbor, and an oath be laid upon him to cause him to swear, and the oath come before thine <span class="kw" id="" style="color: RGBA(10, 0, 0, 0.2); ">altar</span> in this house:<br>
<span style="font-size: smaller; font-weight: bold; vertical-align: text-top;">54</span> And it was so, that when Solomon had made an end of praying all this prayer and supplication unto the LORD, he arose from before the <span class="kw" id="" style="color: RGBA(10, 0, 0, 0.2); ">altar</span> of the LORD, from kneeling on his knees with his hands spread up to heaven.<br>
<span style="font-size: smaller; font-weight: bold; vertical-align: text-top;">62</span> And the king, and all Israel with him, <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ed sacrifice before the LORD.<br>
<span style="font-size: smaller; font-weight: bold; vertical-align: text-top;">63</span> And Solomon <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ed a sacrifice of peace <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings, which he <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ed unto the LORD, two and twenty thousand oxen, and an hundred and twenty thousand sheep. So the king and all the children of Israel dedicated the house of the LORD.<br>
<span style="font-size: smaller; font-weight: bold; vertical-align: text-top;">64</span> The same day did the king hallow the middle of the court that was before the house of the LORD: for there he <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ed <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.8); ">burn</span>t <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings, and meat <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings, and the fat of the peace <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings: because the brazen <span class="kw" id="" style="color: RGBA(10, 0, 0, 0.2); ">altar</span> that was before the LORD was too little to receive the <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.8); ">burn</span>t <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings, and meat <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings, and the fat of the peace <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings.<br>
<br><br><br><span style="font-size: 14px; font-weight: bold;"><a href="http://www.blueletterbible.org/Bible.cfm?b=gen&amp;c=8&amp;t=KJV" target="_blank">Genesis 8</a></span> - <span style="font-size: 14px; font-weight: bold;"><a href="http://www.blueletterbible.org/assets/flash/mp3bibleplayer.cfm?b=1&amp;c=8&amp;t=KJV" target="_blank">Listen</a></span><br>
<span style="font-size: smaller; font-weight: bold; vertical-align: text-top;">20</span> And Noah builded an <span class="kw" id="" style="color: RGBA(10, 0, 0, 0.2); ">altar</span> unto the LORD; and took of every clean beast, and of every clean fowl, and <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ed <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.8); ">burn</span>t <span class="kw" id="" style="color: RGBA(100, 0, 0, 0.4); ">offer</span>ings on the <span class="kw" id="" style="color: RGBA(10, 0, 0, 0.2); ">altar</span>.<br>
</p>

function-give.php (7.6 KB)

Which array is this a dump of, at the top?

print_r($keyword_colorArr);

My eyes keep going square trying to get through the code, but I think this might be a problem. At the start of the function, you open this loop:

for($a=0; $a<count($keyword_colorArr);$a++){

which iterates through that array. However, on line 145 of your code, still within that main loop as far as I can see, you open this second loop:

for($a=0; $a<count($keyword_colorArr);$a++){

It looks to me like that will end with the value of $a equalling count($keyword_colorArr) the first time you run through the loop, so your outer loop exits without running the second (or any subsequent) pass.

you’re probably looking at a repeated section which is blocked. But $keyword_colorArr has 3 arrays nested within eachother. The first level is for the sqls to make their searches:

SELECT * FROM bible WHERE (book = '11' AND chapter= '8') AND (text_data 
LIKE '%altar%' OR text_data LIKE '%offer%' OR text_data LIKE '%burn%') 
ORDER BY id ASC

SELECT * FROM bible WHERE (book = '1' AND chapter= '8') AND (text_data 
LIKE '%altar%' OR text_data LIKE '%offer%' OR text_data LIKE '%burn%') 
ORDER BY id ASC

there has to be a for loop somehow which enters a different group of words in the 2 sqls.

the 2nd and 3rd levels are the words grouped with colors, which are used later for highlighting at the end result.This way each word has a unique color used from the db table.

Line 145 seems to be an inner loop that builds an INSERT query to presumably store stuff in the table you created earlier on. But because you use $a as the count variable for that loop, it destroys that value that the main outer loop (the one that builds those two queries, right at the top of the function) uses because that also uses $a as the counter. Hence it never gets to the second block of keywords, ‘turn’ and ‘unto’ in your post above.

That’s how it appears to me, anyway.

It’s still not working. I brought the 2nd part in the 1st for loop and am getting the same result:

`<?php
function give(){
    global $db, $dbTable3, $spoke, $b1, $c1, $bk2, $ch2, $keyword_color1, $keyword_colorArr, $highlight, $h3, $comments, $commentsarray, $blblinks1, $blblinks2, $result;
    echo $h3; 
    //echo $comments;
    //$count=0;
    //print_r($keyword_colorArr);
    echo "<span style=\"color: blue; \" >";
    echo count($keyword_colorArr);
    //print_r($keyword_colorArr[$j]);
    print_r($keyword_colorArr);
    echo "</span>";
    for($d=0; $d<count($keyword_colorArr);$d++){
        if(isset($keyword_colorArr[$d])!=NULL || isset($keyword_colorArr[$d])!==""){
            $sql9Part = "SELECT * FROM ".$dbTable3." WHERE ";
            //$sql9a .= $sql9Part."(";
            $sql9a = $sql9Part."(book = '" .$b1. "' AND chapter= '" .$c1. "') ";
            $sql9b = $sql9Part."(book = '" .$bk2. "' AND chapter= '" .$ch2. "') ";
            //$sql9 .= ") ";
            if(count($keyword_colorArr[$d]) != 0 ){
                $sql9 = "AND (";
                $sql9a .= $sql9;              
                $sql9b .= $sql9;
                for($j=0; $j < count($keyword_colorArr[$d]);$j++){
                    echo "<span style=\"color: red; \" >";
                    echo count($keyword_colorArr[$d]);
                    //print_r($keyword_colorArr[$j]);
                    print_r($keyword_colorArr[$d][$j]);
                    echo "</span>";
                    if($j>0 && $j > count($keyword_colorArr[$d])-2){
                        $sql9a .= " OR ";              
                        $sql9b .= " OR ";
                    }
                    $sql9a .= "text_data LIKE '%".$keyword_colorArr[$d][$j][0]."%'";
                    $sql9b .= "text_data LIKE '%".$keyword_colorArr[$d][$j][0]."%'";
                    if($j < count($keyword_colorArr[$d])-2){
                        $sql9a .= " OR ";              
                        $sql9b .= " OR ";
                    }
                }
                $sql9a .= ")";
                $sql9b .= ")";
            }
            $sql9a .= " ORDER BY id ASC";
            $sql9b .= " ORDER BY id ASC";
            echo $sql9a."<br />\n";
            echo $sql9b."<br />\n";
    
            // Step 3: Send the query
            $result9a = $db->query($sql9a);
            $result9b = $db->query($sql9b);
            // Step 4: Iterate over the results
            while($row9a = $result9a->fetch(PDO::FETCH_ASSOC)){
                $id9a[] = $row9a['ID'];
                $bookSpoke9a[] = $row9a['book_spoke'];
                $chapterSpoke9a[] = $row9a['chapter_spoke'];
                $verseSpoke9a[] = $row9a['verse_spoke'];
                $bookTitle9a[] = $row9a['book_title'];
                $book9a[] = $row9a['book'];
                $chapter9a[] = $row9a['chapter'];
                $verse9a[] = $row9a['verse'];
                $recordType9a[] = $row9a['recordType'];
                $textData9a[] = $row9a['text_data'];
                $bSpokeCycle9a[] = $row9a['b_spoke_cycle'];
                $cSpokeCycle9a[] = $row9a['c_spoke_cycle'];
                $vSpokeCycle9a[] = $row9a['v_spoke_cycle'];
            }
            while($row9b = $result9b->fetch(PDO::FETCH_ASSOC)){
                $id9b[] = $row9b['ID'];
                $bookSpoke9b[] = $row9b['book_spoke'];
                $chapterSpoke9b[] = $row9b['chapter_spoke'];
                $verseSpoke9b[] = $row9b['verse_spoke'];
                $bookTitle9b[] = $row9b['book_title'];
                $book9b[] = $row9b['book'];
                $chapter9b[] = $row9b['chapter'];
                $verse9b[] = $row9b['verse'];
                $recordType9b[] = $row9b['recordType'];
                $textData9b[] = $row9b['text_data'];
                $bSpokeCycle9b[] = $row9b['b_spoke_cycle'];
                $cSpokeCycle9b[] = $row9b['c_spoke_cycle'];
                $vSpokeCycle9b[] = $row9b['v_spoke_cycle'];
            }
            //var_dump($textData9a);
            //var_dump($textData9b);
        //}
    //}
    
        if(isset($bookTitle9a[0]) || isset($bookTitle9b[0])){    
            $table11 = strtolower($bookTitle9a[0]).$chapter9a[0]."_and_".strtolower($bookTitle9b[0]).$chapter9b[0];
            $table11id = $recordType9a[0].$chapter9a[0]."_and_".$recordType9b[0].$chapter9b[0]."_ID";
        
            $create6 = "CREATE TABLE IF NOT EXISTS ".$table11."
            (".$table11id." int(5) NOT NULL AUTO_INCREMENT PRIMARY KEY,
            date_time DATETIME,
            postorder INT(3),
            spoke INT(3),
            comments varchar(1000),
            joinids varchar(50),
            words varchar(120),
            color varchar(30)
            )";
            
            echo $create6."<br /><br /><br />\n";
            
            $db->exec($create6);
        
            if(count($textData9a)>0 && count($textData9b)>0){        
                // for the first text
                $resultFounda = "";
                for($i=0; $i < count($recordType9a); $i++){
                    $resultFounda .= "<span style=\"font-size: smaller; font-weight: bold; vertical-align: text-top;\">".$verse9a[$i]."</span> ";
                    $strTexta = stripslashes($textData9a[$i]);
                    for($j=0; $j<count($keyword_colorArr[$d]);$j++){        
                        $strTexta = preg_replace("/(".$keyword_colorArr[$d][$j][0].")/i", "<span class=\"kw\" id=\"\" style=\"color: ".$keyword_colorArr[$d][$j][1]."; \">$1</span>", $strTexta);
                    }
                    for($b=0; $b<count($highlight);$b++){
                        for($k=0; $k<count($highlight[$b]);$k++){
                            $strTexta = preg_replace("/(".$highlight[$b][$k][0].")/i", "<span class=\"kw\" id=\"\" style=\"color: ".$highlight[$b][$k][1]."; \">$1</span>", $strTexta);
                        }
                    }
                    $resultFounda .= $strTexta."<br />\n";
                }
        
                /******************************************************************************************************************/
                // for the second text
                //print_r($textData9b);
                $resultFoundb = "";
                for($i=0; $i < count($recordType9b); $i++){
                    $resultFoundb .= "<span style=\"font-size: smaller; font-weight: bold; vertical-align: text-top;\">".$verse9b[$i]."</span> ";
                    $strTextb = stripslashes($textData9b[$i]);
                    for($j=0; $j<count($keyword_colorArr[$d]);$j++){        
                        $strTextb = preg_replace("/(".$keyword_colorArr[$d][$j][0].")/i", "<span class=\"kw\" id=\"\" style=\"color: ".$keyword_colorArr[$d][$j][1]."; \">$1</span>", $strTextb);
                    }
                    for($b=0; $b<count($highlight);$b++){
                        for($k=0; $k<count($highlight[$b]);$k++){
                            $strTextb = preg_replace("/(".$highlight[$b][$k][0].")/i", "<span class=\"kw\" id=\"\" style=\"color: ".$highlight[$b][$k][1]."; \">$1</span>", $strTextb);
                        }
                    }
                    $resultFoundb .= $strTextb."<br />\n";
                }
                //$count=$count+1;    
                $h4 = "";
                //$h4 .= ($count).") ";
                echo "<b>";
                print_r($keyword_colorArr[$d]);
                echo "<br />".count($keyword_colorArr[$d]);
                echo "</b>\n";
                for($i=0; $i < count($keyword_colorArr[$d]); $i++){
                    if($i>0 && $i>(count($keyword_colorArr[$d])-2)){
                        $h4 .= " and ";
                    }else{
                        if($i>0){
                            $h4 .= ", ";
                        }
                    }
                    $h4 .= ucfirst($keyword_colorArr[$d][$i][0]);
                }
                //for($f=0; $f<count($bookSpoke4); $f++){
                for($a=0; $a<count($keyword_colorArr);$a++){
                    if(isset($keyword_colorArr[$a])!=NULL || isset($keyword_colorArr[$a])!==""){
                        $insert11 = "INSERT INTO ".$table11." (
                        date_time,
                        postorder,
                        spoke,
                        comments,
                        words, 
                        color
                        ) VALUES (
                        '".date("Y-m-d H:i:s")."',
                        '',
                        ".$spoke.", ";
    
                        $words = "";
                        //$theColor = "";
                        if(count($keyword_colorArr[$a]) != 0 ){
                            for($j=0; $j < count($keyword_colorArr[$a]);$j++){
                                $words .= $keyword_colorArr[$a][$j][0];
                                //if($j=0){
                                    $theColor = $keyword_colorArr[$a][$j][1];
                                //}
                                if($j < count($keyword_colorArr[$a])-1){
                                    $words .= "-";
                                }
                            }
                            $insert11 .= "'".$commentsarray[$a]."',";
                            $insert11 .= "'".$words."', ";
                            $insert11 .= "'".$theColor."' ";
                            $insert11 .= ")";
                        }
                        //echo $insert11."<br /><br /><br />\n";
                        $db->exec($insert11);
                    }
                    echo "<h4>".$h4."</h4>";
                    //echo $comments;
                    echo "<p>".$commentsarray[$a]."</p>"; //starting from notes-isaiah17-isaiah61.php date 2016-04-09
                    echo "<p class=\"BVerse\">".$blblinks1;
                    echo $resultFounda;
                    echo "<br /><br /><br />";    
                    echo $blblinks2;
                    echo $resultFoundb."</p>";
                    echo "<br /><br /><br />";
                }
            }
            // empty the comments
            $comments = "";
            // empty the arrays
            $id9a = Array();
            $bookSpoke9a = Array();
            $chapterSpoke9a = Array();
            $verseSpoke9a = Array();
            $bookTitle9a = Array();
            $book9a = Array();
            $chapter9a = Array();
            $verse9a = Array();
            $recordType9a = Array();
            $textData9a = Array();
            $bSpokeCycle9a = Array();
            $cSpokeCycle9a = Array();
            $vSpokeCycle9a = Array();
            
            $id9b = Array();
            $bookSpoke9b = Array();
            $chapterSpoke9b = Array();
            $verseSpoke9b = Array();
            $bookTitle9b = Array();
            $book9b = Array();
            $chapter9b = Array();
            $verse9b = Array();
            $recordType9b = Array(); 
            $textData9b = Array();
            $bSpokeCycle9b = Array();
            $cSpokeCycle9b = Array();
            $vSpokeCycle9b = Array();
        }
        unset($keyword_colorArr);
        return $result;
        }
    }
}
?>`

It is difficult to believe that works at all. What a gigantic mess.

It’s a bit hard to tell, but I think this code

        unset($keyword_colorArr);
        return $result;

executes inside your main for() loop, rather than after the loop has completed, so it clears the array and returns the result before it goes to the next iteration. As I count it, at the end of the code you posted you’ve closed one more set of curly braces than you opened.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.