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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Brennan

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

    Functions used: in separate included file (Not Mine provided with
    codecharge)

    function dlookup($table_ name, $field_name, $where_conditio n)
    {
    $sql = "SELECT " . $field_name . " FROM " . $table_name . " WHERE " .
    $where_conditio n;
    return get_db_value($s ql);
    }

    function get_db_value($s ql)
    {
    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("tblSty le", "fldCustomerID" , "fldStyleID=$la st");
    //Get Std Components For This Customer
    $Components = Dlookup("tblcus tomer", "fldPartsStdCos t",
    "fldCustomerID= $CustomerID");
    $StdComponents = unserialize($Co mponents);
    $sParams .= $last;
    $maxC = count($StdCompo nents);

    $sSQL="INSERT INTO tblorderlines (fldPart,fldPar tType,fldStyleI D) 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
    fldPartCostEsti mate='$StdCost' ,fldRequired=1, fldLineTotal=fl dPartCostEstima t
    e Where fldStyleID=$las t AND fldPart=$i";
    $db->query($sSQL) ;
    }
    }
    $sSQL="DELETE FROM tblOrderLines WHERE fldStyleID=$las t AND fldRequired is
    null";
    $db->query($sSQL) ;


Working...