By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,967 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,967 IT Pros & Developers. It's quick & easy.

Help to improve and/or rip to shreds (constructively) my code

P: n/a
Functions used: in separate included file (Not Mine provided with
codecharge)

function dlookup($table_name, $field_name, $where_condition)
{
$sql = "SELECT " . $field_name . " FROM " . $table_name . " WHERE " .
$where_condition;
return get_db_value($sql);
}

function get_db_value($sql)
{
global $db;
$db_look = new DB_Sql();
$db_look->Database = $db->Database;
$db_look->User = $db->User;
$db_look->Password = $db->Password;
$db_look->Host = $db->Host;

$db_look->query($sql);
if($db_look->next_record())
return $db_look->f(0);
else
return "";
}

I feel that instead of adding A 30+ and growing list of components and then
deleting the ones I want I should just add the ones in i need at the
start.
$Component array contains either null if a component is not to be added or
is a number if an item is to be added its key is equal to fldPartID.

// tblstyle AfterInsert Event begin
$last = mysql_insert_id ();
$CustomerID = DLookup("tblStyle", "fldCustomerID", "fldStyleID=$last");
//Get Std Components For This Customer
$Components = Dlookup("tblcustomer", "fldPartsStdCost",
"fldCustomerID=$CustomerID");
$StdComponents = unserialize($Components);
$sParams .= $last;
$maxC = count($StdComponents);

$sSQL="INSERT INTO tblorderlines (fldPart,fldPartType,fldStyleID) SELECT
fldPartID, fldPartType, $last FROM tblcomponents;";
$db->query($sSQL);
for ($i=0; $i<=$maxC; $i++){
$StdCost = $StdComponents{$i};
if($StdCost>0){
$sSQL ="UPDATE tblorderlines SET
fldPartCostEstimate='$StdCost',fldRequired=1,fldLi neTotal=fldPartCostEstimat
e Where fldStyleID=$last AND fldPart=$i";
$db->query($sSQL);
}
}
$sSQL="DELETE FROM tblOrderLines WHERE fldStyleID=$last AND fldRequired is
null";
$db->query($sSQL);
Jul 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.