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      Overall Rating   

Comment on this Code

Your Name
Comment

Recent Comments

"my zipped demo had the ajax script referencing the wrong database include file. the problem has been fixed." - Posted by Sean Dempsey on Sunday Feb 10th, 2008 at 10:02pm

"Something is wrong in the full demo that I`ve downloaded. There isn`t "preheader.php" and the functions "qr" and "ql" in ajax_saveField.php are not defined." - Posted by Israel Bravo on Sunday Feb 10th, 2008 at 3:41am

"Again, this class is amazingly helpful for designing quick and effective admin pages. It can take hours (or even days) from your work" - Posted by Sean Dempsey on Thursday Feb 7th, 2008 at 1:49pm

"Awesome class. How hard would it be to also implement a search box to provide search capability through the selected table." - Posted by flo on Thursday Apr 3rd, 2008 at 9:47am

"A search box would not be too difficult. Please contact me at sean@seandempsey.com if you`d like to hire me for this job" - Posted by Sean on Thursday Jun 5th, 2008 at 9:51am