This is the one I use:
$pid=960;
$school=1;
////Loop through records
$sql=" SELECT id
FROM therapists WHERE eptherapist_master_epid = ‘$pid’
AND eptherapist_active = ‘Y’ ";
sc_lookup(rs,$sql);
foreach ({rs} as $key => $value)
{
$thid = {rs[$key][0]};
//INSERT SQL HERE
}
///Two stage LOOP
$sql=" SELECT studentid as sid FROM classlist LIMIT 5";
sc_lookup(aa,$sql) ;
foreach ({aa} as $key1 => $value)
{
$sid = {aa[$key1][0]};
$sql=" SELECT studentlastname as name FROM classlist WHERE studentid = ‘$sid’ “;
sc_lookup(bb,$sql) ;
foreach ({bb} as $key2 => $value)
{
$name = {bb[$key2][0]};
$sql=” INSERT INTO tablename (field1,field2) VALUES (’$var1’,’$var2’) ";
sc_exec_sql($sql);
}
}