Current Record: Displaying Xataface record values #33

News

Current Record: Displaying Xataface record values #33

News

Click to minimize this section Details

News id 33
Headline Displaying Xataface record values
Content Taking a look at the Xataface Record API presents you with several techniques to display the values of the record. At the lowest level, there is a function called val and can be called like this (assuming $rec is a Xataface record)<br /><br /><blockquote>$rec->val('fieldname')</blockquote><br /><br />What this does is it displays the raw value of field. As in exactly what is stored in the database. <br /><br />But what happens if the value is say a foreign key to another table say like a number of a company. We don't really want to display just the number, but rather the company name of the id. If a valuelist has been setup for this company_id in a valuelist.ini file, then you can easily display the field you really want by simply using the "display" function. <br /><br />So say for example, in your application delegate's valuelists.ini file you have this:<br /><br /><blockquote><br />[companies]<br />__sql__="select company_id,company_name from companies order by company_name"<br /></blockquote><br /><br />So you are basically telling Xataface to use the company_name as a replacement for the company_id. Since this is the application's delegate, this valuelist is accessible by any table and can be overwritten the own table's valuelist. In any case, if in your other table you just call:<br /><br /><blockquote>$rec->display('company_id')</blockquote><br /><br />Xataface will be smart enough to use the company_name in replacement for the company_id. This display function is also useful for database field types datetime, time, or date. If you were simply use the "val" function it would return the date as an array with keys "year", "month", "seconds", etc. And you would be left with having to piece together the information yourself. But by using the display() function you can quickly circumvent this problem.
Image (Empty)
Date posted Sat Aug 2 14:41:00 2008
Posted by noreply@blogger.com (Fong Chun Chan)
Status Approved
Categories Blog
Source id Fong's Blog
Source url http://fongxataface.blogspot.com/2008/08/displaying-xataface-record-values.html
Powered by Xataface
(c) 2005-2024 All rights reserved