![alain01](https://xoops.org/uploads/avatars/cavt5e1e5eed1294e.gif)
Want to see a little part ?
https://codepen.io/alain01/full/dyPEVdG
https://codepen.io/alain01/full/RwNmLKR
Please, try the responsive mode (smartphone, tablet, laptop, desktop)
// get the Access dB departments Name not in XOOPS
$accessQuery1 = "SELECT DEPTID, DEPTNAME FROM DEPARTMENTS WHERE DEPTNAME NOT IN ('$deptNameArray')";
$rs1 = odbc_exec($conn, $accessQuery1);
if (!$rs1) {
exit("Error in SQL");
}
// now update departments into 'mydepartments' table
while(odbc_fetch_row($rs1)){
$deptId=odbc_result($rs1,"DEPTID");
$deptName=odbc_result($rs1,"DEPTNAME");
$updateprocess= $GLOBALS['xoopsDB']->query("UPDATE ".$xoopsDB->prefix("mydepartments")."
SET DEPTNAME='$deptName' WHERE DEPTID='$deptId'");
}
// get the Access dB all departments
$accessQuery2 = "SELECT DEPTID FROM DEPARTMENTS";
$rs2 = odbc_exec($conn, $accessQuery2);
if (!$rs2) {
exit("Error in SQL");
}
// now delete department in 'mytr_departments' table
while(odbc_fetch_row($rs2)){
$deptId2[]=odbc_result($rs2,"DEPTID");
}
$deptIdArray2 = implode(', ', $deptId2);
$deleteprocess=$GLOBALS['xoopsDB']->queryF("DELETE FROM ".$xoopsDB->prefix("mydepartments")."
WHERE DEPTID NOT IN ($deptIdArray2)");
UPDATE mydepartments AS mydepartments, departments AS departments
SET mydepartments.DEPTNAME = departments.DEPTNAME
WHERE departments.DEPTID = mydepartments.DEPTID;
// first get a list of department IDs
$result=$GLOBALS['xoopsDB']->query("SELECT DEPTID FROM ".$xoopsDB->prefix("mydepartments")."");
while($row=$GLOBALS['xoopsDB']->fetchArray($result))
{$deptId[]=$row['DEPTID'];}
$deptIdArray = implode(', ', $deptId);
// connect to the Access dB
$conn = odbc_connect('mydata','','');
if (!$conn) {
exit("Connection Failed: " . $conn);
}
// now get the Access dB departments not in XOOPS
$accessQuery = "SELECT DEPTID, DEPTNAME FROM DEPARTMENTS WHERE DEPTID NOT IN ($deptIdArray)";
$rs = odbc_exec($conn, $accessQuery);
if (!$rs) {
exit("Error in SQL");
}
// now put new departments into 'mydepartments' table
while(odbc_fetch_row($rs)){
$deptId=odbc_result($rs,"DEPTID");
$deptName=odbc_result($rs,"DEPTNAME");
$resultx= $GLOBALS['xoopsDB']->query("INSERT INTO ".$xoopsDB->prefix("mydepartments")."(`DEPTID`, `DEPTNAME`)
VALUES ('$deptId','$deptName')");
if (!$resultx) {
redirect_header($_SERVER['PHP_SELF'], 2, 'Error inserting new department');
exit();
}
++$i;
}
redirect_header($_SERVER['PHP_SELF'], 2, "{$i} new departments entered into the database");
exit();
goffy wrote:
Hi mjoel
I do it always the other way around (because I am very familiar with access :) )
I link the mysql tables via odbc into my ms access database (only mysql-driver is necessary).
Then you can handle the data in the access db.
// first get a list of department IDs
$result = $GLOBALS['xoopsDB']->query('SELECT DISTINCT(DEPTID) FROM ' . $GLOBALS['xoopsDB']->prefix('mydepartments'));
list($deptIdArray) = $GLOBALS['xoopsDB']->fetchRow($result);
// connect to the Access dB
$conn = odbc_connect('mydata','','');
if (!$conn) {
exit("Connection Failed: " . $conn);
}
// now get the Access dB departments not in XOOPS
$accessQuery = "SELECT DEPTID, DEPTNAME FROM DEPARTMENTS WHERE DEPTID NOT IN (" . implode(',', $deptIdArray) . ")";
$rs = odbc_exec($conn, $accessQuery);
if (!$rs) {
exit("Error in SQL");
}
// now put new departments into 'mydepartments' table
while(odbc_fetch_row($rs)){
list($deptId, $deptName) = odbc_result($rs, 'DEPTID', 'DEPTNAME');
$result = $GLOBALS['xoopsDB']->query("INSERT INTO " . $xoopsDB->prefix('mydepartments') . "($deptId, $deptName)");
if (!$result) {
exit('Error inserting new department');
}
++$i;
}
}
exit("{$i} new departments entered into the database");
$GLOBALS['xoopsDB']->
$xoopsDB->
implode(',', 'deptIdArray')
implode(',', $deptIdArray)
// first get a list of department IDs
$result = $GLOBALS['xoopsDB']->query('SELECT DISTINCT(DEPTID) FROM ' . $GLOBALS['xoopsDB']->prefix('mydepartments'));
list($deptIdArray) = $GLOBALS['xoopsDB']->fetchRow($result);
// connect to the Access dB
$conn = odbc_connect('mydata','','');
if (!$conn) {
exit("Connection Failed: " . $conn);
}
// now get the Access dB departments not in XOOPS
$accessQuery = "SELECT DEPTID, DEPTNAME FROM DEPARTMENTS WHERE DEPTID NOT IN (" . implode(',', 'deptIdArray') . ")";
$rs = odbc_exec($conn, $accessQuery);
if (!$rs) {
exit("Error in SQL");
}
// now put new departments into 'mydepartments' table
while(odbc_fetch_row($rs)){
list($deptId, $deptName) = odbc_result($rs, 'DEPTID', 'DEPTNAME');
$result = $GLOBALS['xoopsDB']->query("INSERT INTO " . $xoopsDB->prefix('mydepartments') . "($deptId, $deptName));
if (!$result) {
exit('Error inserting new department');
}
++$i;
}
}
exit("{$i} new departments entered into the database");