PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old January 2nd, 2003, 08:47 PM
invoke invoke is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 6 invoke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Problem - Passing arrays to PHP/JS page

Hi everyone,

I've got a strange problem with an application I'm working on. The problem is around the passing of two arrays to a PHP/JavaScript page.

What I'm doing is creating two arrays, one to check if the menu element is enabled, and the other to give the element a URL link.

I then urlencode() and serialize() each array and pass it through a class which writes the JS script tag into the page with the URL and encoded array as variables.

The JS page then does an unserialize() and stripslashes() on each array. After which I step through the array with a for loop and do some checking etc. Finally the JS page echo's the correct <span> and link to each element.

Now that all works and I've done a half dozen menu's that work fine. The problem is happening when I go over 10 elements in the arrays. It's just throwing a JS error and not displaying the menu.

So I was wondering if there is a limit to the size of passed arrays? I've not found anything at php.net to indicate this. Or if there is somthing else that may cause such a problem.

Anyway here's the code associated with the problem broken down into the three pages.

Page 1 (page that display's the menu)
The commented out array elements are ones that cause the problems. As you can see there's nothing different about them it's just that it's adding an eleventh element to each array.
PHP Code:
<?php
$areaName 
"project";

$itemCheck2[] = "true";
$itemCheck2[] = "true";
$itemCheck2[] = "true";
$itemCheck2[] = "true";
$itemCheck2[] = "true";
$itemCheck2[] = "true";
$itemCheck2[] = "true";
$itemCheck2[] = "true";
$itemCheck2[] = "true";
$itemCheck2[] = "false";
//$itemCheck2[] = "true";

$itemURL2[] = "<a href=\\"../link1.php" $linkStyle>";
$itemURL2[] = "<a href=\\"../link2.php" $linkStyle>";
$itemURL2[] = "<a href=\\"../link3.php" $linkStyle>";
$itemURL2[] = "<a href=\\"../link4.php" $linkStyle>";
$itemURL2[] = "<a href=\\"../link5.php" $linkStyle>";
$itemURL2[] = "<a href=\\"../link6.php" $linkStyle>";
$itemURL2[] = "<a href=\\"../link7.php" $linkStyle>";
$itemURL2[] = "<a href=\\"../link8.php" $linkStyle>";
$itemURL2[] = "<a href=\\"../link9.php" $linkStyle>";
$itemURL2[] = "<a href=\\"../link10.php" $linkStyle>";
//$itemURL2[] = "<a href=\\"../link11.php\\" $linkStyle>";
    
$passCheck2 urlencode(serialize($itemCheck2));
$passURL2 urlencode(serialize($itemURL2));
$jsVarString2 "passCheck2=$passCheck2&passURL2=$passURL2";
    
$page->pageOpenMenu($areaName,$jsVarString2);
?>

Page 2 (Class script that I use as a template)
PHP Code:
<?php
function pageOpenMenu($areaName,$jsVarString2){
    global 
$browserTypeSession;
    echo
"<script language=\"JavaScript\" type=\"text/javascript\">\n
    document.write(\"<SCRIPT LANGUAGE='JavaScript' src='../javascript/main_$areaName/$browserTypeSession.php?$jsVarString2' TYPE='text/javascript'></SCRIPT>\");\n
    </script>\n"
;
}
?>

Page 3 (The JavaScript page)
PHP Code:
<?php
$disable 
"<span class=projectmenuDisabled>";
$enable "<span>";

$itemCheck2 unserialize(stripslashes($passCheck2));
$itemURL2 unserialize(stripslashes($passURL2));

$comptItemCheck2 count($itemCheck2);
for(
$i=0;$i<$comptItemCheck2;$i++){
    if(
$itemCheck2[$i] == "true"){
        
$phpCheck2[$i] = $enable;
        
$phpURL2[$i] = $itemURL2[$i];
    }else{
        
$phpCheck2[$i] = $disable;
        
$phpURL2[$i] = "";
    }
}

?>

This is what I'm using to echo the spans and links in the JS page. It's strange I know but with the large size of the script all of which has to be on one line it's the only way I've found to make it echo correctly.
PHP Code:
<?php echo"$phpCheck2[0]"?><?php echo "$phpURL2[0]"?>


Thanks all

Reply With Quote
  #2  
Old January 3rd, 2003, 02:12 AM
hadley hadley is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 63 hadley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
1. You don't seem to have escaped all your quotes correctly.

2. Where is the javascript?

3. Have you checked (by printing to the screen) that the serialized strings are the same on each page? This would check that it's a problem with your code rather than the strings being truncated.

Hadley

Reply With Quote
  #3  
Old January 3rd, 2003, 04:01 AM
invoke invoke is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 6 invoke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for replying Hadley,

The code I actually have in the array looks like this:
$itemURL2[] = "<a href=\\\"../projects/viewproject.php?display=projectdetails&id=$id&$transmitSid\\\" $linkStyle>";//Details

I just realised that putting it in the php forum tags kind of messes with it. Strange with so many slashes but it works

Anyhow I've found out that the problem is the length of the URL string. I've tested it own two blank pages that just pass arrays. I can get to a total of 26 elements before it won’t allow breaks down and won’t allow the page to progress. So my problem at the moment is that I need to send 100 variables between pages, whilst keeping it an acceptable length.

If anyone has any ideas I would love to hear them

I'm looking at doing some checks inside the php in the JS file instead of passing variables. I hope that will work okay.

Reply With Quote
  #4  
Old January 4th, 2003, 08:39 AM
hadley hadley is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 63 hadley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Hmmm. Strange, I didn't think URL strings had any practical limit.

You might want to think about passing the data around some other way: using forms and POST, through a text file or database.

Hadley

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Problem - Passing arrays to PHP/JS page


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway