Warning: include_once(/home/loudcanv/public_html/includes/location_functions.php): failed to open stream: Permission denied in /home/ajaxcrud/public_html/preheader.php on line 44

Warning: include_once(): Failed opening '/home/loudcanv/public_html/includes/location_functions.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/ajaxcrud/public_html/preheader.php on line 44
ajaxCRUD.com » ajaxCRUD API :: defineRelationship - Use PHP & AJAX to CRUD from a mysql database table (create / read / update / delete)


» a PHP class to Create, Read, Update, & Delete from a mysql database table using AJAX

   by loud canvas media

AjaxCRUD Class Documentation / Reference Material

<< Reference overview
<< Home


defines a relationship between your table and another (via the foreign key)
void defineRelationship ( String dbMainTableFK, String dbOtherTable, String dbOtherTablePK, String dbOtherTableField, [ String dbOtherTableSortField = ""], [ INT required = 1 ], [String whereClause=""] )
This function sets the "allowable" values in a dropdown box for a 1-Many relationship. Your dropdown VALUE will be the foreign key and the option TEXT will be the field of your choosing in the associated table.


Type function
Returns void


Foreign key of the main table
Name of the associated table (table you're making a relationship to)
Primary key of the associated table (this is the VALUE of the dropdown)
Field to return for the TEXT in the dropdown
(optional) dbOtherTableSortField
The name of the field in the associated table you wish to sort by (eg fldSort)
(optional) required
0 to make this field not require one of the choices (default) | 1 to require one be selected
(optional) whereClause
a where clause for the associated table to use


$tblDemo->defineRelationship("fkOtherTableID", "tblOtherTable", "pkOtherTableID", "fldOtherTableField");

OR (w/advanced features)

$tblDemo->defineRelationship("fkOtherTableID", "tblOtherTable", "pkOtherTableID", "fldOtherTableField", "fldSort", 0, "WHERE fldOtherTableName LIKE 'Libertarian%'");


$tblDemo->defineRelationship("fkOtherTableID", "tblOtherTable", "pkOtherTableID", "CONCAT(fldFirstName, " ", fldMiddleName, " ", fldLastName)")

See also

New, Edit


"I have been using php like 5 years ago, but it feels like it is 20 years ago :-) Now I have found an incredible module AjaxCRUD and damn, this is nice!"

What is a business/commercial website?

A commercial website is one created for a business, for which purpose is generating revenue or cash flow of any type (and that isn't under a non-profit organization). So if you're selling a product, selling advertisement, selling a service, or just marketing a commercial business, your site is commercial. A company website is also commercial even if it doesn't sell anything, as it's purpose is to front a commercial company.