Hi,
You can post multidimensional arrays to PHP for example in an HTML
form, this is better than GET which may have a lower limit on the number
of characters that can be sent in a request (as I found out with some
JQuery stuff)...
http://php.net/manual/en/reserved.variables.post.php
http://www.php.net/manual/en/reserved.variables.post.php#96902
You can do:
<input name="myArray[0][id]" value="123"/>
So in Flash you could do the same by setting the appropriate
variables in a URLVariables, but note, you probably have to call your
variables something like this:
var data:URLVariables = new URLVariables();
data["myArray[0][id]"] = 123;
So you could loop through your datagrid and submit the values that
way - you would need to add a "count" variable which tells PHP how many
objects are in your array, then you could do:
<?php
$num_items = isset($_POST['num_items']) ?
(int)$_POST['num_items'] : 0;
for($i = 0; $i < $num_items;$i++) {
$id = $_POST["myArray"][$i]["id"];
//...
}
?>
Alternatively - and less data-intensively, you could save the
values every time someone changes a field and then it loses focus. You
would have to save each variable separately so you would need a form
processor that handles some kind of id, a variable name and a value that
you then add / update in the database (if there is no id field, you
could be inserting data).
You could use Sephiroth's serialiazer system:
http://www.sephiroth.it/test/unserializer/
Or some other way of dealing with the data like AMF, etc.
There used to be some good stuff on Flash DB
http://www.flash-db.com/, but it appears to be down now, so maybe it has
gone the way of many websites...
I think there are lots of libraries that do a lot of the crappy
grunt work for you with Flash -> Database stuff so whilst it's good to
learn the principles, you would possibly benefit from finding something
like these in the long run, especially where security is concerned:
http://www.php.net/manual/en/security.database.php
Hope this helps you a little.
If only you could assign an object to URLVariables and have it post
properly....
Glen
On 06/09/2011 04:04, Cor wrote:
Thanks Karl,
Yes, I know.
My problem is how to fetch my $_POST['VALUES'], which is the
multi-dimensional array:
myArray[0["id"]
myArray[0]["name"]
myArray[0]["description"]
myArray[1["id"]
myArray[1]["name"]
myArray[1]["description"]
myArray[2["id"]
myArray[2]["name"]
myArray[2]["description"]
etc.
Best regards,
Cor van Dooren
-----Original Message-----
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl
DeSaulniers
Sent: dinsdag 6 september 2011 3:54
To: Flash Coders List
Subject: Re: [Flashcoders] DataGrid: save multidim arrayfrom Flash to mySQL
with PHP
Hi Cor,
Assuming you know enough php to set up the file for connecting to your
database, you can insert into your database with the following example.
function addDescription($id, $name, $description) {
//Escape any data being inserted
$id = mysql_real_escape_string($id);
$name = mysql_real_escape_string($name);
$description = mysql_real_escape_string($description);
$query = "INSERT INTO YOUR_TABLE_NAME_HERE VALUES ('".$id."','".
$name."','".description."')";
$_POST['VALUES'];
$result = mysql_query($query, YOUR_CONNECTION) or
die(mysql_error());
return $result; //Returns true or false if error }
HTH,
Best,
Karl
On Sep 5, 2011, at 2:04 PM, Cor wrote:
I have a editable datagrid which I fill from mySQL with PHP.
So far works good.
But when items are changed (edit, added, deleted), I want them to save
the data in my mySQL database.
My values are in this multi-dimensional indexed array, which elements
all contain a associative array:
myArray[i]["id"]
myArray[i]["name"]
myArray[i]["description"]
So, can anyone tell/show me a apropriate way to pass this to PHP and
in the php-file how to INSERT or UPDATE this to mySQL?
TIA!
Best regards,
Cor van Dooren
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Karl DeSaulniers
Design Drumm
http://designdrumm.com
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders