ajaxCRUD.com
» a PHP API to create / read / update / delete from a database table using AJAX
by loud canvas mediaQuick Links:
Quick Examples:
- Creating a Relationship
- File Uploading
- Using a Where Clause
- Defining Allowable Input
- Formatting Fields With Function
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 |
|---|---|---|---|---|
| sdfrtyrty | hkjkbn,b | NEW Value | dfsfsdf3 | |
| jihj | klown | kaloon | looooooong | |
| 444 | qwernb,mbn | newjhgjhg | gvcvcvbcvb | |
| poppy | folky | My Awesome Value | yo! | |
| fffruuyu- | NEW Value | |||
| bal | bal | bal | bal |
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
Leave a Comment
"I love AjaxCRUD! It's saved me hours upon hours of typing!"
~Eric Duwenhoegger
"AjaxCRUD is wonderful."
~Peter Barone

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