# Actionscript/PHP/MySQL - How to Write Array Items to Individual Dbase Rows

**URL:** <https://forum.kirupa.com/t/actionscript-php-mysql-how-to-write-array-items-to-individual-dbase-rows/279061>\
**Category:** programming\
**Created:** [January 8, 2009, 11:50pm UTC](https://forum.kirupa.com/t/actionscript-php-mysql-how-to-write-array-items-to-individual-dbase-rows/279061 "2009-01-08T23:50:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)\
**Post date:** [January 8, 2009, 11:50pm UTC](https://forum.kirupa.com/t/actionscript-php-mysql-how-to-write-array-items-to-individual-dbase-rows/279061/1 "2009-01-08T23:50:27Z")

</div>

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):

```auto

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):

```auto

var PHPVarsSender:LoadVars = new LoadVars();
PHPVarsSender.soldItem = soldItemNum;
PHPVarsSender.sendAndLoad("php/saveToDbase.php",PHPVarsSender,"POST");

```

saveToDbase.php

```auto

<?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.

```auto

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.
