ajaxCRUD.com
» a PHP API to create / read / update / delete from a database table using AJAX
Create a Relationship Example
Consider the following tables (and SQL insert statements):
CREATE TABLE tblGenres(
pkGenreID INT PRIMARY KEY AUTO_INCREMENT,
fldGenre VARCHAR(40)
);
CREATE TABLE tblMyMp3CollectionDemo2(
pkMP3ID INT PRIMARY KEY AUTO_INCREMENT,
fldFilename VARCHAR(150),
fldTitle VARCHAR(60),
fldArtist VARCHAR(60),
fkGenreID INT
);
INSERT INTO tblGenres (fldGenre) VALUES ("Rock");
INSERT INTO tblGenres (fldGenre) VALUES ("Pop");
INSERT INTO tblGenres (fldGenre) VALUES ("Euro Trash");
INSERT INTO tblGenres (fldGenre) VALUES ("Sweedish HipHop");
| fldFilename | fldTitle | fldArtist | fkGenreID | Action |
|---|---|---|---|---|
| aaa | Rock | |||
| A | 2 | 777 | Rock | |
| n | b | v | Euro Trash | |
| Rock | ||||
| 11 | fvdfv | 33 | Pop |
Class Implementation:
#include the class
include ('ajaxCRUD.class.php');
#this one line of code is how you implement the class
$tblDemo = new ajaxCRUD(
"MP3 File", "tblMyMp3CollectionDemo2", "pkMP3ID");
$tblDemo->defineRelationship("fkGenreID", "tblGenres", "pkGenreID",
"fldGenre");
$tblDemo->omitPrimaryKey();
#actually show to the table
$tblDemo->showTable();
View Example by Itself
Click here to view example outside of the template.
Recent Feedback
"Looks efficient. I`m going to go try it out..." - Posted by Jason R on Friday Jul 11th, 2008 at 4:32pm
"Just perfect ..." - Posted by Besmir S on Thursday Jul 17th, 2008 at 7:51pm
"Perfect. I`m go try it
Amigo" - Posted by Horacio from méxico on Tuesday Aug 12th, 2008 at 3:23pm
Amigo" - Posted by Horacio from méxico on Tuesday Aug 12th, 2008 at 3:23pm
"comment3, " - Posted by jonn2 on Saturday Nov 8th, 2008 at 12:22am
Leave a Comment