Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro 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 November 8th, 2006, 04:47 PM
Registered User
 
Join Date: Nov 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Losing data in a php array.. please help!

I have a .php file that has php, html, and javascript in it. at the very top of the file, I use PHP to pull data from my a mySQL database, and put it into a PHP array.

after some HTML code, I have some javascript to put the PHP array into a javascript array.

What is weird, is that at top, my PHP array is completely filled(about 25,000) entries. However, once I use it again(assigning it to a javascript array), and it only has 14 elements!(everything else gets lost, so when I try to assign more than 14 elements in my array, it doesn't work)

below is my code:
[PHP SECTION]
<?
    $rows = array();
    $cou = 0;
    $test = mysql_query("SELECT title from Pamphlet");
    while($row = mysql_fetch_array($test))
    {
        $rows[$cou] = $row[0];
        $cou++;
        if($cou < 30)
            echo $row[0].'<br />';
    }
    //echo $rows[2];
?>
[THEN SOME HTML]

[JS SECTION]
<script language="Javascript">
     var a = new Array();
    var i = 0;

    <?php
    $k = 14;
    for($j = 0; $j < $k; $j++)
    {
    ?>
        i = <?=$j?>;
        a[i] = ('<?php echo $rows[$j] ?>');
    <?php
    }
    ?>

    function bindEvents()
    {
        //Find all of the INPUT tags
        var tags = document.getElementsByTagName('INPUT');
        for (i in tags)
        {
            var tag = tags[i];
                //If it's a text tag, attach an AutoSuggest object.
            if(tag.type && tag.type.toLowerCase() == "text")
            {
                new AutoSuggest(tag,a);
            }
        }
    }


    window.onload = bindEvents;
</script>

This only works if my $k is 14 or less. If it is more than 14, or if I use a foreach, it doesnt work. Am I losing data from the top of my .php file to the bottom of it? I know that javascript runs on the user side and php on the browser side, is this what is causing my errors!?

Thanks for any help!
-Josh






Similar Threads
Thread Thread Starter Forum Replies Last Post
Losing special character data mussitsch Classic ASP Professional 4 September 5th, 2006 02:29 PM
Storing form array data to MySQL using PHP osemollie Beginning PHP 0 February 2nd, 2006 07:32 AM
RSS Feed to PHP in Array? sami PHP How-To 1 April 17th, 2005 04:53 PM
Passing php array values to javascript array gkrishna Pro PHP 0 November 6th, 2004 03:20 AM
Constantly losing PHP session variable? achalasia PHP How-To 3 October 29th, 2004 09:08 AM





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