ajaxCRUD.com
» a PHP class to create / read / update / delete from a database table using AJAX
by loud canvas mediaQuick Links:
Quick Examples:
- Displaying Images
- Creating a Relationship
- File Uploading
- Using a Where Clause
- Defining Allowable Input
- Formatting a Field With a Function
- Show Header Checkbox
www.allthewebsites.org
Format Field With Function
Consider the following table:
CREATE TABLE tblDemo(
pkID INT PRIMARY KEY AUTO_INCREMENT,
fldField1 VARCHAR(40),
fldField2 VARCHAR(40),
fldField3 VARCHAR(40),
fldCertainFields VARCHAR(40),
fldLongField TEXT
);
| fldField1 | fldField2 | fldCertainFields | fldLongField | Action |
|---|---|---|---|---|
| asdf | asdf | This is another Value | hola | |
| dsaf | asdf | OLD Value | asdf | |
| 1 | 2 | andres | 123 |
Class Implementation:
#include the class
include ('ajaxCRUD.class.php');
#this one line of code is how you implement the class
$tblDemo = new ajaxCRUD("New Item", "tblDemo", "pkID");
$tblDemo->omitPrimaryKey();
$tblDemo->formatFieldWithFunction('fldField1', 'makeBlue');
$tblDemo->formatFieldWithFunction('fldField2', 'makeBold');
#actually show to the table
$tblDemo->showTable();
function makeBold($val){
return "<b>$val</b>";
}
function makeBlue($val){
return "<span style='color: blue;'>$val</span>";
}
View Example by Itself
Click here to view example outside of the template.
Recent Feedback
"haha. wow. i never knew this existed!" - Posted by Jason on Saturday Apr 17th, 2010 at 9:47pm
Leave a Comment
"wow. that`s all I can say. Wow. I wish I had found this .... years ago.."
~Jake

" - Posted by gustavo on Friday Jan 8th, 2010 at 11:45am