FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » General » PHP discussions » losing data in PHP array... please help!
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
losing data in PHP array... please help! [message #34598] Wed, 08 November 2006 20:56 Go to previous message
jfern is currently offline  jfern   United States
Messages: 2
Registered: November 2006
Location: New York
Karma:
Junior Member
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
[Message index]
 
Read Message
Read Message
Previous Topic: Message Tree
Next Topic: Shopping cart malfunction?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 13:12:03 GMT 2024

Total time taken to generate the page: 0.05175 seconds