Disclaimer: This class is horrible! I know it’s horrible. There is not much use for it when dealing with large data sets, but it’s handy for creating HTML from a list of records in a database, etc for things like a HTML select statement, etc.
Implements a list of table
objects.
Parent Class
None
Public Properties
Data Type: string
Default Value: Empty string
table
objectsData Type: array
Default Value: Empty array
Public Methods
Parameters:
$tableName
(string: required) is the name of the database table you will be using to build this databaseList
Returns:
A
databaseList
instanceExample:
1 2 |
$myList = new \ipinga\databaseList('actors'); // creates a database list from the records in the actors table $myList->load(); // actually does the loading of the table records |
databaseList
object.Parameters:
$orderBy
(string: optional) is the field name to order the records by. Default: idReturns:
null
Example:
1 2 |
$myList = new \ipinga\databaseList('actors'); // creates a database list from the records in the actors table $myList->load(); // actually does the loading of the table records |
databaseList
object.Parameters:
$where
(string: required) is the where clause used to load the records$orderBy
(string: optional) is the field name to order the records by. Default: idReturns:
null
Example:
1 2 3 |
$myList = new \ipinga\databaseList('actors'); // creates a database list from the records in the actors table $myList->loadWithWhere('client_id=1'); // actually does the loading of the table records. // In this case, only those records with a client_id of 1 |
databaseList
that do not match the required filterParameters:
$filter is an associate array of fieldnames and values to use as the filter
Returns:
null
Example:
1 2 3 |
$myList = new \ipinga\databaseList('actors'); // creates a database list from the records in the actors table $myList->load(); $myList->filter( array( 'client_id' => 1 ) ); // This is a painfully slow and inefficient way of filtering large databases! |
databaseList
Parameters:
$selectName
(string: required) is the value that will be used as the HTML select’s name attribute$fieldName
(string: required) is the name of the field to display as a choice for the user$selectedId
(integer: optional) is the id value for the currently selected record. Default=0$addFirst
(boolean: optional) if true will cause the phrase “Select one…” to be added as the first option statement in the HTML select code. Default=false$class
(string: optional) is the value that will be used as the HTML select’s class attribute. Default=noneReturns:
An HTML string of code that is the select statement
Example:
1 2 3 |
$myList = new \ipinga\databaseList('actors'); // creates a database list from the records in the actors table $myList->load(); echo $myList->asHtmlSelect('who','first_name'); |
Parameters:
None.
Returns:
A json encoded string
Example:
1 2 3 |
$myList = new \ipinga\databaseList('actors'); // creates a database list from the records in the actors table $myList->load(); echo $myList->asJson(); // outputs a list of all records in json format |
databaseList
Parameters:
$fieldName
(string: required) is the name of the field to test$value
(mixed: required) is the value to select from the recordsReturns:
A
table
object for the record that matches the $value or false if no record is foundExample:
1 2 3 4 5 6 |
$myList = new \ipinga\databaseList('actors'); // creates a database list from the records in the actors table $myList->load(); $tbl = $myList->recordByField('first_name', 'NICK'); // locates the first record with a first name of Nick. echo $tbl->last_name; // outputs: whatever Nick's last name is |
databaseList
. This is very similar to the function above, but returns the record id instead of the actual record.Parameters:
$fieldName
(string: required) is the name of the field to test$value
(mixed: required) is the value to select from the recordsReturns:
An integer value for the id field of the record that was located, or zero if no record was found.
Example:
1 2 3 4 5 6 |
$myList = new \ipinga\databaseList('actors'); // creates a database list from the records in the actors table $myList->load(); $num = $myList->recordNumberByField('first_name', 'NICK'); // locates the first record with a first name of Nick. echo $num; // outputs: whatever the id was for the first Nick in the list |