why script only updating one table?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi All,
 
I have a form that passes to select box array to my script. Select boxes
are named:
 
patternThreads[] and patternFabrics[]
 
My Script:
 
//Check to see if Threads were selected for this pattern
if ($patternThreads)
 
{
if (is_array($patternThreads))
                {
                                $str_threads =
implode(",",$patternThreads);
                }
                else
                {
                                $str_threads = $patternThreads;
                }
                $threadsArray = explode(",",$str_threads);
 
                for ($i=0;$i<sizeof($threadsArray);$i++) {
 
                                //Grab a listing of all threads
currently in the DB
                                //associated with the pattern
 
$allthreadsQuery = db_query("SELECT id FROM kcs_patternthreads WHERE
pattern_index='$id' AND thread_index=".escapeValue($threadsArray[$i]));
 
                                //Does a record already exist?
 
                                if (db_numrows($allthreadsQuery) < 1)
                                {
                                                //No? Insert a new
record for each new keyword selected
db_query("INSERT INTO kcs_patternthreads
(id,pattern_index,thread_index,avail) VALUES
('','$id',".escapeValue($threadsArray[$i]).",'0')");
 
                                }
 
                }
 
                //Check to see if a thread was unchecked.
                //If so, delete entry from DB
 
$db_threads1 = db_query("SELECT * FROM kcs_patternthreads WHERE
pattern_index='$id'");
 
                while($db_threads2 = db_fetch($db_threads1))
 
                $db_threads[] = $db_threads2[thread_index];
 
                foreach($db_threads AS $thread) {
 
                                if(!in_array($thread, $threadsArray))
 
db_query("DELETE FROM kcs_patternthreads WHERE pattern_index='$id' AND
thread_index='$thread'");
                }
}
 
 
//Check to see if fabrics were selected for this pattern
if ($patternFabrics)
{
                if (is_array($patternFabrics))
                {
                                $str_fabrics =
implode(",",$patternFabrics);
                }
                else
                {
                                $str_fabrics = $patternFabrics;
                }
                $fabricsArray = explode(",",$str_fabrics);
 
                for ($i=0;$i<sizeof($fabricsArray);$i++) {
 
                                //Grab a listing of all fabrics
currently in the DB
                                //associated with the pattern
 
$allfabricsQuery = db_query("SELECT id FROM kcs_patternfabrics WHERE
pattern_index='$id' AND fabric_index=".escapeValue($fabricsArray[$i]));
 
                                //Does a record already exist?
 
                                if (db_numrows($allfabricsQuery) < 1)
                                {
                                                //No? Insert a new
record for each new keyword selected
db_query("INSERT INTO kcs_patternfabrics
(id,pattern_index,fabric_index,avail) VALUES
('','$id',".escapeValue($fabricsArray[$i]).",'0')");
 
                                }
                }
 
                //Check to see if a fabric was unchecked.
                //If so, delete entry from DB
 
$db_fabrics1 = db_query("SELECT * FROM kcs_patternfabrics WHERE
pattern_index='$id'");
 
                while($db_fabrics2 = db_fetch($db_fabrics1))
 
                $db_fabrics[] = $db_fabrics2[fabric_index];
 
                foreach($db_fabrics AS $fabric) {
 
                                if(!in_array($fabric, $fabricsArray))
 
db_query("DELETE FROM kcs_patternfabrics WHERE pattern_index='$id' AND
fabric_index='$fabric'");
                }
 
}
 
The scrip is supposed to see if either select box contains data and then
process the data.
 
Does anyone understand why it would be updating only one table at a time
and not both at the same time? It should be updating both at the same
time!
 
NOTE: if I remove the processing code for either select box it works
without problem. They just don't seem to work together.
 
Thanks!
 
Aaron

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux