
Originally Posted by
Tony Marston
AFAIAA there is no duplicate code in any of my classes. I have taken all reusable code and put it into separate functions that can be called from anywhere. That is one of the reasons why there are so any small functions within my classes.
from option.class.inc:
PHP Code:
function getValRep ($item = 'option_id')
// get Value/Representation list from this table
// custom method to obtain table contents as an associative array
{
$array = array();
if (strtolower($item) == 'option_id') {
// get data from the database
$this->sql_select = 'option_id, option_desc';
$this->sql_orderby = 'option_id';
$this->sql_ordery_seq = 'asc';
$this->rows_per_page = 0; // turn off pagination
$data = $this->getData(null);
// start array with blank entry
$array[' '] = '';
// convert each row into 'id=desc' in the output array
foreach ($data as $row => $rowdata) {
$rowvalues = array_values($rowdata);
$array[$rowvalues[0]] = $rowvalues[1];
} // foreach
return $array;
} // if
return $array;
} // getValRep
from tree_type.class.php:
PHP Code:
function _cm_getValRep ($item = '')
// get Value/Representation list as an associative array.
{
$array = array();
if (strtolower($item) == 'tree_type_id') {
// get data from the database
$this->sql_select = 'tree_type_id, tree_type_desc';
$this->sql_orderby = 'tree_type_id';
$this->sql_ordery_seq = 'asc';
$this->rows_per_page = 0; // turn off pagination
$data = $this->getData(null);
// start array with blank entry
$array[' '] = '';
// convert each row into 'id=desc' in the output array
foreach ($data as $row => $rowdata) {
$rowvalues = array_values($rowdata);
$array[$rowvalues[0]] = $rowvalues[1];
} // foreach
return $array;
} // if
return $array;
} // _cm_getValRep
from pers_type.class.php:
PHP Code:
function getValRep ($item = 'pers_type_id')
// get Value/Representation list from this table
// custom method to obtain table contents as an associative array
{
$array = array();
if (strtolower($item) == 'pers_type_id') {
// get data from the database
$this->sql_select = 'pers_type_id, pers_type_desc';
$this->sql_orderby = 'pers_type_id';
$this->sql_ordery_seq = 'asc';
$this->rows_per_page = 0; // turn off pagination
$data = $this->getData(null);
// start array with blank entry
$array[' '] = '';
// convert each row into 'id=desc' in the output array
foreach ($data as $row => $rowdata) {
$rowvalues = array_values($rowdata);
$array[$rowvalues[0]] = $rowvalues[1];
} // foreach
return $array;
} // if
return $array;
} // getValRep
These are obvious examples of duplicate code, my opinionated friend. It took me longer to download the sample than it did to find duplicate code. I found several examples of copy and pasted duplicate code in minutes and i didn't even have to do a search.
I also have to say you have some brilliant naming.
PHP Code:
require_once 'include.inc';
and helpful comments
PHP Code:
// initialise session
initSession();

Originally Posted by
Tony Marston
While working for a software house in the mid-1980s
sounds like the 80s were good to you. What kind of a haircut do you have?
Bookmarks