Database Table PHP Class - Page 2

Back to page 1 | Back home page


As of 5/10/08 this class has been upgraded and renamed to ajaxCRUD --> a full API (and download) is available at ajaxCRUD.com.



To implement the PHP class in your code simply use the following TWO LINES:

$tblFAQ = new Database_Table("FAQ", "tblFAQ", "pkFAQID");
$tblFAQ->showTable();

The class takes 3 (three) parameters:

  1. The first is what each element in the table IS (for example, in this case, it's a table of FAQs). Make sure the parameter is the singular noun.
  2. The second parameter is the name of the table you wish to display.
  3. The third parameter is the primary key for each element in the table. (If this is in any way confusing, please reference database design elements for more information on the purposes of primary keys.)

Voila. You now have a functioning database-driven application. Pretty nifty.

The class can take a variety of other function calls. They are described as follows:

# define a 1-M relationship between this table and another
$tblFAQ->defineRelationship("fkCategoryID", "tblFAQCategory", "pkCategoryID", "fldName", "fldSort");

#params:
  • 1 = foreign key in the table
  • 2 = table name that you're building the relationship
  • 3 = primary key of the table you're building the relationship
  • 4 = name of the field you want to display for the relationship
  • 5 = field to sort by (optional)

# display a field name as an alias
$tblFAQ->displayAs("fldQuestion", "Question");

#params:
  • 1 = field name
  • 2 = alias to give to field

# omits a field from displaying
$tblFAQ->omitField('fldSort');

# disallows a field from being editable
$tblFAQ->disallowEdit('fldAnswer');
# omits a field from being added when New Item is pressed
# this field must be optional in your table (can't be NOT NULL)
$tblFAQ->omitAddField('fldSort');

#params:
  • 1 = field name

# omits the primary key from displaying in the table
$tblFAQ->omitPrimaryKey();

# disallows the deletion of any row (removes the button)
$tblFAQ->disallowDelete();

# disallows the adding of new rows
$tblFAQ->disallowAdd();
# sets the limit of rows to appear on a page $tblFAQ->setLimit(20);

View demo again.

Download full demo


Previous Page


Your Rating