Display custom fields data in an HTML table
来源:互联网 发布:软件开发测试工程师 编辑:程序博客网 时间:2024/06/12 05:24
Today, here is a simple TXP PHP script I would like to share with you.
For my latest project I needed to display a price list in an HTML table based on corresponding articles. My articles refer to products. I use custom fields to store special descriptions informations and prices. These custom fields are named like this:
- Table_Line_1
- Table_line_2
- (…) and so on (…)
These simple text inputs are populated by a semi-colon separated list of information:
String 1 ; String 2 ; price 1 ; price 2 ; price 3
Into the template for my “Prices” page, I put my html markup table and use an article_custom tag to call a form named “inner_table_builder” (type misc). Following is the script to grab all the custom fields data and display it in multiple table rows.
The script
<txp:php>
/*** @script: display each rows from the 10 custum fields article** @copyright: cara-tm, http://cara-tm.com* @licence: Creative Common 2, http://creativecommons.org/licenses/by-nc-nd/2.0/fr/deed.en_US* @author Patrick LEFEVRE <patrick[dot]lefevre[at]gmail[dot]com>* @version 1.03**/
// uncomment below if u want to use local currency format for prices
//setlocale(LC_MONETARY, 'fr_FR@euro');
// grab needed global variables from core. get current article's title
global $thisarticle;$title = $thisarticle['title'];
// loop for main table datas. Query on custom fields
for($i=1; $i<10; $i++) {$line = safe_rows('Title, custom_'.$i.'', 'textpattern', 'Title = "'.$title.'"');
// avoid blank fields
if(!empty($line[0]['custom_'.$i])) {
// start display table inner structure
echo '<tr class="line">';echo '<td class="left">'.$line[0]['Title'].'</td>';
// place custom fields into an array
$el = explode(";", $line[0]['custom_'.$i]);
// display array content based on keys
echo '<td class="center">'.$el[0].'</td>';echo '<td class="center">'.$el[1].'</td>';
/*simple currency format with number_format function (prices are writting with a comma decimal value)use instead : htmlentities(money_format('%.2n',$line3[4]),ENT_QUOTES,'ISO-8859-15')*/echo '<td class="center">'.number_format(str_replace(',','.',$el[2]),2, ',', ' ').' €</td>';echo '<td class="center">'.number_format(str_replace(',','.',$el[3]),2, ',', ' ').' €</td>';echo '<td class="center">'.number_format(str_replace(',','.',$el[4]),2, ',', ' ').' €</td>';echo '</tr>';}
}
// uncomment below if locale currency formating is used
// setlocale(LC_MONETARY, '');</txp:php>
You’ve now got your product information displayed in an HTML table. All changes made to the custom fields are updated.
- Display custom fields data in an HTML table
- Display Custom Fields in a Content By Query Web Part
- Custom fields of Organization in Liferay
- Reference Pivot Fields and Pivot Items in an Excel Pivot Table, using VBA
- Convert HTML Table to an Array in Python
- Read and Display Data From an Excel File (.xsl or .xlsx) in ASP.NET
- Display of CDPOS fields VALUE_OLD, VALUE_NEW in SE16
- Display fields as checkbox, pushbutton, dropdownbox in ALV
- How to display fields in the frontend item view
- An example to show how to make Tree structure data table in SQL server
- Need custom data field in mysql
- Creating custom data graphics in Visio
- Custom Search Match Fields
- Display row number in af:table
- Extracting data in Table maintenance
- Display Sum Total in Data Grid
- SD--Adding Custom Fields to VBAP and VBAK / Additional data B screen
- Custom pushpin HTML in bingMap v7.0
- oracle sql语言模糊查询
- 影响网页样式错乱的因素
- javascript判断是否数字、整数
- USB描述符详解
- 简介SubMain的两个有用工具
- Display custom fields data in an HTML table
- Android TextView 设置超链接、关键字高亮等效果
- CyanogenMod源码下载和编译(Android ROM定制基础篇)
- 转 字符串处理函数
- 2014辞岁迎新—广州传智播客Java培训教学研讨会
- TOME开发框架1.0.0(PHP框架)
- 使用Ant实现zip/tar的压缩与解压
- Merge Two Sorted Lists
- 倒计时