Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 8th, 2006, 04:47 PM
Registered User
Join Date: Nov 2006
Location: , , .
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:
    $rows = array();
    $cou = 0;
    $test = mysql_query("SELECT title from Pamphlet");
    while($row = mysql_fetch_array($test))
        $rows[$cou] = $row[0];
        if($cou < 30)
            echo $row[0].'<br />';
    //echo $rows[2];

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

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

    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;

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!

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 08:09 PM.

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