Sections

Home
Technology
About

About

Welcome to E-Dude.org!

The place for everything about your friend/colleague/enemy!

Enjoy!

Tycho

Twittered

Links

Google
Ultimum

Endorced

 Use OpenOffice.org

Proclamation

Hacker

Powered by

Powered by Pivot - 1.40.6: 'Dreadwind'
XML: RSS Feed
XML: Atom Feed

Search::

179 W - + 1 - 2 Javascript array annoyance from database results

A common thing done in webdevelopment is using data from a database.
In your average PHP code you'd just do a while( list( ,$val ) = each( $dbResult ) ) loop, maintaining the correct order for the query results.

Now for the twist!

If you want to quite literally use your query result, an array of rows with their associated fields and values, in Javascript you can't really convert that one-to-one.

So, what's the solution?

Simple!

You make an array and a function to add the rows to your result!
Unfortunately, you can not just add it automatically to the array, so you need some kind of loop.

Here's an example:
[quote]
function newRow ( id, value )
{
this.id = id;
this.value = value;
}

var myTable = new Array();

myTable[0] = new newRow( 1, "User1" );
myTable[1] = new newRow( 2, "User2" );
[/quote]

You can generate that list quite easily in any programming language and/or templating engine and you can use it to feed it to all of your functions as well.
Because it's based on objects, you get to use entry.name too!
  
Remember personal info?

Emoticons / Textile

To prevent automated comment spam we require you to answer this silly question.

What are the first two letters of the word 'spam'?

 

  (Register your username / Log in)

Notify:
Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.