A
Anonymous
Guest
I have a query which selects particular fields from one table and inserts to a different table. Here is my query:
Is there a better way to do this?
Thanks for all help
Code:
$sql = "SELECT college, deptname, fulltitle, coursedsc,
prereq, cip1, cip2, cip3, cip4, prefix,
crsnumber, sptopics, shorttitle, chkgrade,
degcredit, repcredit, lecture, lab,
credithrs, type
FROM table 1 WHERE change_id > 0 ORDER BY change_id ASC ";
$result = mysql_query($sql, $conn)
or die ("Cannot execute query");
while ($records = mysql_fetch_array($result)){
//This is to skip any single quote(s) present in text fields
$deptname_clean = htmlspecialchars($records['deptname'], ENT_QUOTES);
$fulltitle_clean = htmlspecialchars($records['fulltitle'], ENT_QUOTES);
$coursedsc_clean = htmlspecialchars($records['coursedsc'], ENT_QUOTES);
$prereq_clean = htmlspecialchars($records['prereq'], ENT_QUOTES);
$shorttitle_clean = htmlspecialchars($records['shorttitle'], ENT_QUOTES);
//Build query
$sql_insert = "INSERT INTO table2
(college, deptname, fulltitle, coursedsc, prereq, cip1,
cip2, cip3, cip4, prefix, crsnumber, sptopics, shorttitle,
chkgrade, degcredit, repcredit, lecture, lab, credithrs, type)
VALUES(
'$records[college]', '$deptname_clean', '$fulltitle_clean',
'$coursedsc_clean', '$prereq_clean', '$records[cip1]',
'$records[cip2]','$records[cip3]', '$records[cip4]',
'$records[prefix]', '$records[crsnumber]', '$records[sptopics]',
'$shorttitle_clean', '$records[chkgrade]', '$records[degcredit]',
'$records[repcredit]', '$records[lecture]', '$records[lab]',
'$records[credithrs]', '$records[type]') ";
Is there a better way to do this?
Thanks for all help