Skip to main content

In PHPRUNNER, how to import excel with column “Project Status”. In column “Project Status” user key-in “status” but before import to table it will automatic replace with id.

Table= “project”
Field= “project_status_id

Table= “project_status”
field= “id” (primary key)
field= “status

File excel
Column= “Project Status


//————-LOOKUPS VALUES OF PROJECT STATUS IN EXCEL BEFORE IMPORT TO TABLE DATABASE—————–
// Lookup project status before importing to the database
$status = $rawvalues[“project_status_id“];

// Query the project_status table to find the corresponding ID
$sql = “SELECT id FROM project_status WHERE status = ” . db_prepare_string($status);
$data_status = db_fetch_array(db_query($sql, $conn));

// If matching ID found, replace project_status_id with the ID, otherwise show error
if ($data_status) {
$values[“project_status_id“] = $data_status[“id“];
} else {
$message = “Status ‘$status’ not found in the database.”;
return false;
}