09 08 08 179 W - + 27 - 21 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!
Good post! Thanks for sharing with us, I’ll recommend it to all my friends!
cheap coach bags (Email) (URL) - 19 02 11 - 12:23
Does anyone know if the Dyson DC25 animal ball vacuum is any good?
My kid broke my other one and we to buy a new Dyson DC25 animal ball
Thanks for your help!
- Sheila
Dyson Animal Ball Upright Vacuum (Email) (URL) - 13 06 11 - 08:49
it’s a good article!
coach sneakers (Email) (URL) - 08 07 11 - 08:20
I learned a lot from this post, much appreciated! :)
Donna Machine
(Email) (URL) - 23 08 11 - 13:25