I have a form where you can assign multiple licenses to a piece of hardware. The problem I am having is that my while loop it only running on the first record found from the SWLIC field. I am sure I am missing something obvious and if someone could point me in the right direction I would appreciate it.
I have this code on the AfterInsert Event to update the license count for all :
$array = explode (";",{swLic}); //swlic are the values from double select on form
$arrayLength = count($array);
$x=0;
while ($x < $arrayLength)
{
$softID=$array[$x];
echo $softID;
// GET SOFTWARE COUNT
$licenseCount = "SELECT count(softwareID) FROM license_hw
where softwareID = $array[$x]";
sc_lookup(ds,$licenseCount);
$swcount= {ds[0][0]};
echo $swcount;
//end GET SOFTWARE COUNT
//Update Count
// SQL statement parameters
$update_table = 'software'; // Table name
$update_where = "idsoftware = $softID"; // Where clause
$update_fields = array( // Field list, add as many as needed
"assignedLic = $swcount",
);
// Update record
$update_sql = 'UPDATE ' . $update_table
. ' SET ' . implode(', ', $update_fields)
. ' WHERE ' . $update_where;
sc_exec_sql($update_sql);
//END UPDATE COUNT
$x++;
}