Formatting info and displaying it in crud
- Single Page
Posted 23 April 2012 - 16:05 PM
I was wondering if there was a way to format a column of information form the database. I have some old tables that do the formatting and echo html table that formats certain fields like dates, prices, and frequency of payments, but I want to put it into a grocery crud table.
Originally the code for it was this:
[php]
function getLocationLease($location_id) {
$retStr = "";
$sqlStr = "SELECT * FROM `location_lease` ll LEFT JOIN manufacturer m on (ll.manufacturer_id=m.manufacturer_id) WHERE ll.location_id='" . $location_id . "'";
$result = $this->db->query($sqlStr);
if($result->num_rows()>0) {
foreach($result->result() as $row){
$lease_start_date = $this->fixDate($row->start_date);
$lease_end_date = $this->fixDate($row->end_date);
if ($row->amount != 0)
$lease_amount = "$". number_format($row->amount, 2, '.', ',');
else
$lease_amount = "-";
$lease_status = $this->convertStatus($row->status);
$retStr = $retStr. "";
$retStr = $retStr. "<span style="font-weight: bold;"> ". $row->name ."</span>";
$retStr = $retStr. "". $row->number . "";
$retStr = $retStr. "".$row->term ."";
$retStr = $retStr. "". $lease_start_date ."";
$retStr = $retStr. "". $lease_end_date . "";
$retStr = $retStr. "". $lease_amount ."";
$retStr = $retStr. "". $this->frequencyConvert($row->frequency) ."";
$retStr = $retStr. "". $lease_status ."";
$retStr = $retStr. "";
}
}
else
{
$retStr = $retStr. "";
$retStr = $retStr. " No lease information found.";
$retStr = $retStr. "";
}
return $retStr;
}
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
function convertStatus($locStatus) {
if ($locStatus)
$ret = "Active";
else
$ret = "Not active";
return $ret;
}
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
function fixDate($strDate) {
if( $strDate =="0000-00-00")
$ret="-";
else
$ret= date('m/d/Y',strtotime($strDate));
return $ret;
}
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
function frequencyConvert($frequency){
$strRet="";
switch ($frequency){
case 1:
$strRer="Monthly";
break;
case 3:
$strRer="Quarterly";
break;
case 6:
$strRer="Bi-annual";
break;
case 12:
$strRer="";
}
return $strRer;
}
[/php]
I think I may be going about this the wrong way and I can't figure it out. I've tried using the set_model() to make a table:
[php]<?php
class Loc_disp_crud_model extends grocery_Model
{
function get_list()
{
if($this->table_name === null)
return false;
$select = "{$this->table_name}.*";
// ADD YOUR SELECT FROM JOIN HERE <------------------------------------------------------
$select .=", manufacturer.name, location_lease.number, location_lease.term, location_lease.start_date, location_lease.end_date, location_lease.amount, location_lease.frequency, location_lease.status";
// for example $select .= ", user_log.created_date, user_log.update_date";
if(!empty($this->relation))
foreach($this->relation as $relation)
{
list($field_name , $related_table , $related_field_title) = $relation;
$unique_join_name = $this->_unique_join_name($field_name);
$unique_field_name = $this->_unique_field_name($field_name);
if(strstr($related_field_title,'{'))
$select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name";
else
$select .= ", $unique_join_name.$related_field_title as $unique_field_name";
if($this->field_exists($related_field_title))
$select .= ", {$this->table_name}.$related_field_title as '{$this->table_name}.$related_field_title'";
}
$this->db->select($select, false);
// ADD YOUR JOIN HERE for example: <------------------------------------------------------
$this->db->join('manufacturer','manufacturer.manufacturer_id = location_lease.manufacturer_id');
// $this->db->join('user_log','user_log.user_id = users.id');
$results = $this->db->get($this->table_name)->result();
return $results;
}[/php]
Can someone please help me with this
Posted 24 April 2012 - 15:12 PM
...but I'm trying to put the code into an iframe now and it doesn't seem to work. When I call the iframe in the view and load the page it says
--------------------------------------
[b] Forbidden[/b]
[color=#000000]
You don't have permission to access /enterprise/<div style= on this server.[/color][color=#000000]
-------------------------------[/color]
[color=#000000]
It shows up where the table is supposed to be and I can't get it to go away.[/color]
[color=#000000]
...The weird thing is that the table does show up still, at the top of the page and pushes the entire website down. Which is how I know that my code does in fact work and that the table does the conversion [/color]
[color=#000000]
Does anyone have any idea how to get rid of this error?[/color]
Posted 26 April 2012 - 17:55 PM
like in my database had a field called amount and a cell had a number of 1300.45... how could i get it to display 1300.45 to $1300.45 without changing the database?
Posted 26 April 2012 - 18:12 PM
For your case you probably just need to do:
return '$'.$value;
in the callback function.