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

This is a discussion on Help to improve and/or rip to shreds (constructively) my code within the PHP Language forums, part of the PHP Programming Forums category; Functions used: in separate included file (Not Mine provided with codecharge) function dlookup($table_name, $field_name, $where_condition) { $sql = "SELECT " . $...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-21-2003
David Brennan
 
Posts: n/a
Default 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_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);


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:57 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0