homepage Welcome to WebmasterWorld Guest from 184.73.40.21
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
2d arrays - ajax - mysql
Creating 2d arrays on the fly for database storage later
PSWorx

10+ Year Member



 
Msg#: 3674693 posted 9:43 am on Jun 14, 2008 (gmt 0)

Im in the process of databasing a desktop style cms interface for the web, its pretty similar to an average desktop (windows/linux/mac) when creating a new "window" i want to store its dimensions in an array which will have to be 2 dimensions, 1'st d to relate to the window, 2nd d to store its dimensions and any other information.

I want to store this in the actual html content of the page during the windows use (to avoid too many connections to the database) then on closing of the window i will update the database with the relative data.

How would i go about doing this?

Any ideas will be helpfull.

TIA

 

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3674693 posted 2:26 pm on Jun 14, 2008 (gmt 0)

I think you really need to be looking backend for this, Perl or PHP.

But on the client side, you really need to be looking a lot further than 2 dimensions, consider this structure:


// First a var to store your page
var allWindows;

// You'll need to store the x and y sizes separately
allWindows[0]['windowname']['size'][0] = 400;
allWindows[0]['windowname']['size']= 200;

// Then colour, font, etc... and anything else
allWindows[0]['windowname']['colour'] = "#BBBBBB";
allWindows[0]['windowname']['font'] = "Verdana";

[1][edited by: Dabrowski at 2:32 pm (utc) on June 14, 2008]

PSWorx

10+ Year Member



 
Msg#: 3674693 posted 11:42 am on Jun 15, 2008 (gmt 0)

Im ok with the server side (php and mysql) of things, i just need some pointers on how to create a javascript array that will be located/updated within a script tag inside the html document body or head tag im relatively alright with javascript but not entirely sure how i would go about this.

This is my understanding:

To create an array thats accessible by any of the scripts (global in php speak) that need to create, amend or destroy a windows data reference (my terminology is crap so bare with me)

The array would be stored in a <script></script> tag either in the body of the html document or in the head depending on accessability issues

Would this be correct?

If so ill plod on with a mock up of what im looking for minus the ajax bits for updating the database n give it a whirl n post here for confirmation of correctness.

TIA

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3674693 posted 12:33 pm on Jun 15, 2008 (gmt 0)

All JavaScript on a page is 'global' (OLN excepted but you really don't need to be touching that!), so here's an example that would create the structure above. Sorry if it's more complicated that you asked for, but as you're an established coder anyway you'll have no problem understanding the syntax....

<script>
// NOTE the characters are broken!

var allWindows = new Array();

function aWindow( name, x, y, colour, font) {
this.name = name;
this.size = new Array( x 100, y 100); // Size is 100x100 by default
this.colour = colour "#000000"; // Black by default
this.font = font "Arial"; // Arial by default
}

function createNewWindow( newWindowName, x, y, colour, font) {
allWindows.push( new aWindow( newWindowName, x, y colour, font));
}
</script>

Actually that's slightly different from above, in practice this way works much better.

So, allWindows is an array of all your windows.
aWindow is a function that creates a window object with name, size, colour and font properties.
createNewWindow is a function that extends the allWindows array by adding another object.

So you'll end up with:
allWindows[0].name = "yourname";
allWindows[0].size[0] = 100;
allWindows[0].size[1] = 100;
allWindows[0].colour = "#000000";
allWindows[0].font = "Arial";

You can put that piece of script anywhere on the page, although the preference if this code is going to be of considerable size, it to use an external JS file to keep your code tidy.

NOTE it is very important that you don't use the word 'window' in your code, as this refers to the top level DOM object, and if you redefine it you'll essentially destroy the current page in the browser. It would be helpful if you could come up with a terminology other than window!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved