I’m making modifications to a “simple” shopping cart - Flash/Actionscript 2.0 interface with PHP acting as the intermediary with a MySQL database. I can insert individual strings of data into the database, but there are going to be multiple number strings to deal with, and I need to split the array of numbers so they can be written to individual rows of the database. Here are the various code parts:
In Flash, retrieve the numbers saved to a Shared Object (cookie):
var soldItemSO:SharedObject = SharedObject.getLocal("soldItems", "/");
var soldItemNum:Array = [];
for (var i:Number = 1; i <= 10; i++) {
if (soldItemSO.data* != undefined) {
soldItemNum[i - 1] = soldItemSO.data*;
trace(soldItemSO.data*);
/*
Displays:
12122003
01101993
01121994
01131994
*/
}
}
Then send the results to a PHP page (this sends the entire array of numbers, so only works if I send a single number):
var PHPVarsSender:LoadVars = new LoadVars();
PHPVarsSender.soldItem = soldItemNum;
PHPVarsSender.sendAndLoad("php/saveToDbase.php",PHPVarsSender,"POST");
saveToDbase.php
<?php
$artwork = $_POST['soldItem'];
$link = mysql_connect("dbase","user","password") or die ("Unable to connect to database.");
mysql_select_db("gallery", $link) or die (mysql_error());
$sqlstatement = "INSERT INTO products (artwork) VALUES ('$artwork')";
$query = mysql_query($sqlstatement, $link);
mysql_close($link);
echo "Data Inserted";
?>
Haven’t tried it yet, but I might be able to use a loop in Flash to send a sequence of data items, but I wonder if this is better done within the PHP. I get the feeling this would just jam up on the server-side.
var PHPVarsSender:LoadVars = new LoadVars();
for (var i:Number = 1; i <= 10; i++) {
PHPVarsSender.soldItem* = soldItemNum*;
PHPVarsSender.sendAndLoad("php/saveToDbase.php",PHPVarsSender,"POST");
}
So the big question: If I send a variable “soldItem” to PHP that contains an array of numbers, “12122003,01101993,01121994,01131994”, how would I extract these individually and write each number to a separate row of the database table? Any advice would be appreciated.