I added an Iframe with a specific Form to list all Items that are assigned to a project.
The data will be collected by selecting the data from different tables and writing the result in a temp table by following code in the BEFORE BROWSE custom code of the Items Form:
Code: Select all
// Temp Table
$create = "CREATE TABLE #TABLE_ID# ";
// get items from assigned project
$q = 'SELECT pro_items FROM project WHERE project_id = "' . "#tas_project#" . '";';
$x = nuRunQuery($q);
$y = db_fetch_object($x);
$items = $y->pro_items;
$items = str_replace(']', '',str_replace('[', '', $items)); // remove [ and ] from the result
// create temp TABLE
if ($items != ""){
$qry = 'SELECT * FROM item WHERE item_id IN (' . $items . ')'; // get data
nuRunQuery($create.$qry); // create temp table
}
But if there are no results I got following error in the debug log because the temp table will not be created:
Code: Select all
1st Debug entry:
__________________________________________
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db195572x3263722.___nu1614ec21204891___' doesn't exist
===SQL===========
SELECT COUNT(*) FROM (SELECT item_id,ite_label,ite_status,ite_manufacturer,ite_model,ite_saler
FROM ___nu1614ec21204891___ END
WHERE 1) nuTCount
__________________________________________
2nd debug entry:
__________________________________________
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db195572x3263722.___nu1614ec21204891___' doesn't exist
===SQL===========
SELECT item_id,ite_label,ite_status,ite_manufacturer,ite_model,ite_saler
FROM ___nu1614ec21204891___ END
WHERE 1 LIMIT 0, 7
Are there any solutions how to avoid the error?IF (EXISTS (#TABLE_ID#))
BEGIN
SELECT * FROM #TABLE_ID#
END
BR, Oli