Manage() provides data management functionality for your application and/or process.
Below is the code for Manage():
//
// Manage()
//
// This function performs simple record functions of add, delete and gets
//
function Manage($ses) {
print("\t<h4>MANAGE</h4>\n");
// delete any existing records
Delete_Records($ses);
// populate the table with data
Add_Records($ses);
// display contents of table
Display_Records($ses);
}
//
// Delete_Records()
//
// This function deletes all the records in the table
//
function Delete_Records ($ses) {
print("\t\tDelete records...<br>\n");
$qry = ctsql_query("DELETE FROM custmast", $ses);
if (!$qry)
if (100 == ctsql_errno())
return;
else
Handle_Error("ctsql_query(DELETE)");
if (!ctsql_commit($ses))
Handle_Error("ctsql_commit()");
}
//
// Add_Records()
//
// This function adds records to a table in the database from an
// array of strings
//
function Add_Records ($ses) {
print("\t\tAdd records...<br>\n");
$data = array(
"('1000','92867','CA','1','Bryan Williams','2999 Regency','Orange')",
"('1001','61434','CT','1','Michael Jordan','13 Main','Harford')",
"('1002','73677','GA','1','Joshua Brown','4356 Cambridge','Atlanta')",
"('1003','10034','MO','1','Keyon Dooling','19771 Park Avenue','Columbia')"
);
foreach ($data as $values) {
$qry = ctsql_query("INSERT INTO custmast VALUES $values", $ses);
if (!$qry)
Handle_Error("ctsql_query(INSERT)");
}
if (!ctsql_commit($ses))
Handle_Error("ctsql_commit()");
}
//
// Display_Records()
//
// This function displays the contents of a table.
//
function Display_Records ($ses) {
print("\t\tDisplay records...<br>\n");
$qry = ctsql_query("SELECT cm_custnumb \"Number\", cm_custname \"Name\" FROM custmast", $ses);
if (!is_resource($qry))
Handle_Error("ctsql_query(SELECT)");
else {
print("\t\t<TABLE border=1>\n\t\t\t<TR><TH>Number</TH><TH>Name</TH></TR>\n");
while ($values = ctsql_fetch_row($qry)) {
print("\t\t\t<TR>");
foreach ($values as $content) {
if (is_null($content))
print ("<TD>NULL</TD>");
else
print ("<TD>$content</TD>");
}
print("</TR>\n");
}
print("\t\t</TABLE>\n");
if (ctsql_errno())
Handle_Error("ctsql_fetch_row()");
ctsql_free_result($qry);
}
}