ajaxCRUD.com

» a PHP API to create / read / update / delete from a database table using AJAX

   by loud canvas media

Quick Links:

Quick Examples:



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
    );


fldField1fldField2fldCertainFieldsfldLongFieldAction
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

"Very interesting class. Thanks a lot. A little suggestion: when I edit a cell, but leaving the original value, an Error message says:"Error updating content.". It would be easier if `Cancel` button nor Error message appear.

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

Leave a Comment

Your Name      
Your Email   
Comment

 

"I love AjaxCRUD! It's saved me hours upon hours of typing!"
~Eric Duwenhoegger

"AjaxCRUD is wonderful."
~Peter Barone