Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 26th, 2018, 11:28 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default why json_encode( all of a sudden stopped encoding the php arrays

I'm stuck on why json_encode( all of a sudden stopped encoding the php arrays int JavaScript arrays. It shows them empty.

PHP Code:
    $js_data = Array();

    for($i=0;$i<count($newStrongsResult);$i++){
        
        $searchStrongs = "SELECT * FROM ".$dbTable13." WHERE strongs = '".$newStrongsResult[$i]."' AND ";
        $searchStrongs .= "(";
        $searchStrongs .= " (book = '".$getB1."' AND chapter = '".$getC1."') OR ";
        $searchStrongs .= " (book = '".$getB2."' AND chapter = '".$getC2."') ";
        $searchStrongs .= ")";
        $searchStrongsResult = $conn->query($searchStrongs);
        
        while($row = $searchStrongsResult->fetch(PDO::FETCH_ASSOC)) {
            $searchStrongs_id[$i][] = $row['id'];
            $searchStrongs_book[$i][] = $row['book'];        
            $searchStrongs_bookTitle[$i][] = $row['book_title'];
            $searchStrongs_recordType[$i][] = $row['recordType'];        
            $searchStrongs_chapter[$i][] = $row['chapter'];
            $searchStrongs_verse[$i][] = $row['verse'];
            $searchStrongs_bookSpoke[$i][] = $row['book_spoke']; 
            $searchStrongs_chapterSpoke[$i][] = $row['chapter_spoke']; 
            $searchStrongs_verseSpoke[$i][] = $row['verse_spoke'];
            $searchStrongs_textData[$i][] = $row['text_data'];        
            $searchStrongs_strongs[$i][] = $row['strongs'];
            $searchStrongs_transliteration[$i][] = $row['transliteration'];
            $searchStrongs_etymology[$i][] = $row['etymology'];
            $searchStrongs_etymStrongs[$i][] = $row['etym_strongs'];
            $searchStrongs_etymDesc[$i][] = lcfirst($row['etym_desc']);
            $searchStrongs_hebWord[$i][] = hebrevc($row['heb_word']);
            $searchStrongs_added[$i][] = $row['added'];
            $searchStrongs_also[$i][] = $row['also'];
        }
        
        $joinedTextData = "('".implode("', \n'", $searchStrongs_textData[$i])."')\n\n";
        
        $joinedTransliteration = "('".implode("', \n'", $searchStrongs_transliteration[$i])."')\n\n";
        $joinedHebrewword = "('".implode("', \n'", $searchStrongs_hebWord[$i])."')\n\n";
        $joinedStrongs_etymDesc = "('".implode("', '", $searchStrongs_etymDesc[$i])."')\n\n";
        
        $joined_Transliteration_Hebrewword_Strongs_etymDesc = Array();
        
        for($j=0;$j<count($searchStrongs_transliteration);$j++){
            $joined_Transliteration_Hebrewword_Strongs_etymDesc = Array(    
                $searchStrongs_transliteration[$j][0],
                $searchStrongs_hebWord[$j][0],
                $searchStrongs_etymDesc[$j][0]);
        }

        $js_data[] = Array($i, $newStrongsResult[$i], $joinedTextData, count($searchStrongs_textData[$i]), $joined_Transliteration_Hebrewword_Strongs_etymDesc, $searchStrongs_added[0], $searchStrongs_also[0], $colors[$i]);
    }

/**************************************/
<?php /*?>
        $id[] = $row['id'];
        $book[] = $row['book'];        
        $bookTitle[] = $row['book_title'];
        $recordType[] = $row['recordType'];        
        $chapter[] = $row['chapter'];
        $verse[] = $row['verse'];
        $bookSpoke[] = $row['book_spoke']; 
        $chapterSpoke[] = $row['chapter_spoke']; 
        $verseSpoke[] = $row['verse_spoke'];
        $textData[] = $row['text_data'];        
        $strongs[] = $row['strongs'];
        $transliteration[] = $row['transliteration'];
        $etymology[] = $row['etymology'];
        $etymStrongs[] = $row['etym_strongs'];
        $etymDesc[] = lcfirst($row['etym_desc']);
        $hebWord[] = hebrevc($row['heb_word']);
        $added[] = $row['added'];
        $also[] = $row['also'];
<?php */
?>    

var js_text1 = <?php echo json_encode($js_text1); ?>;

var js_text2 = <?php echo json_encode($js_text2); ?>;

<?php /*?> 
    0    $i, 
    1    $newStrongsResult[$i], 
    2    $joinedTextData, 
    3    count($searchStrongs_textData[$i]), 
    4    $joined_Transliteration_Hebrewword_Strongs_etymDesc, 
    5    $searchStrongs_added[0], 
    6    $searchStrongs_also[0], 
    7    $colors[$i]
<?php */
?>

var js_data = <?php echo json_encode($js_data); ?>;

var js_newStrongsResult = [<?php echo '"'.implode('","'$newStrongsResult).'"' ?>]; //$php_array





Similar Threads
Thread Thread Starter Forum Replies Last Post
php stopped handling errors gkman BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 4 February 19th, 2012 01:27 PM
PHP array_push() for associative arrays mcmahonc Beginning PHP 1 January 9th, 2010 01:13 PM
HOW TO USE STRINGS,ARRAYS AND VARIABLES IN PHP jhan316 Beginning PHP 1 July 25th, 2006 07:17 PM
php compare 2 arrays lucian PHP How-To 0 February 23rd, 2006 12:53 PM
Mysql,PHP and arrays swedge MySQL 1 February 15th, 2006 07:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.