Welcome Guest, Not a member yet? Register   Sign In
active record with column name spaces
#1

[eluser]xeroblast[/eluser]
to start, i created mysql column names with spaces because i needed it for headers in the HTML Table library ( http://ellislab.com/codeigniter/user-gui...table.html ).

i have a solution in getting the data by disabling the backticks in select query

Code:
$columns = '`column 1`,`column 2`';
$this->db->select($columns, FALSE);

now, for the insert query, how do i disable the backticks. the 3rd parameter for
Quote:$db->set()
is for the value, not the key. hoping there was a 4th parameter that disable the backticks for keys.

thanks. hope anyone could help.
#2

[eluser]skunkbad[/eluser]
[quote author="xeroblast" date="1333429311"]to start, i created mysql column names with spaces because i needed it for headers in the HTML Table library ( http://ellislab.com/codeigniter/user-gui...table.html ).

i have a solution in getting the data by disabling the backticks in select query

Code:
$columns = '`column 1`,`column 2`';
$this->db->select($columns, FALSE);

now, for the insert query, how do i disable the backticks. the 3rd parameter for
Quote:$db->set()
is for the value, not the key. hoping there was a 4th parameter that disable the backticks for keys.

thanks. hope anyone could help.[/quote]

Why not just use some php and have normal column names? It couldn't be easier to name your column names with underscores and remove them for display. You could even use ucfirst() if you want to capitalize the name. You're just shooting yourself in the foot when you go with bizarre column names. I know because one of the projects I am working on now is spec work, and the column names have made things a lot harder than they had to be.

Code:
$name_without_underscores = str_replace('_','','some_name_with_underscores_in_it');
#3

[eluser]xeroblast[/eluser]
thanks for the reply and i already had that solution but i dont have any idea where & how to change the headers for displaying purposes according to the HTML Table library.

as stated in the HTML Table library
Code:
$this->load->library('table');
$query = $this->db->get('mytable');
echo $this->table->generate($query);

how do i use the ucfirst() or str_replace() on this statements if the column names dont have spaces?

thanks again
#4

[eluser]InsiteFX[/eluser]
Build your own CI table template in your controller, then you add your query records to it before generating the table!
#5

[eluser]xeroblast[/eluser]
what do you mean template? write the headers first "$table->set_heading()"? then add the data "$table->add_rows()"?

if that's what you mean then it might give a problem for other tables with different columns. there are different tables that i need to display by using the HTML Table library.

the admin to my program can create a new tables in the database according to his options (it's like phpmyadmin). and let the users use that newly created database to a single controller, model & view. so the only template i could use is the UI template for tables.

thanks
#6

[eluser]InsiteFX[/eluser]
Here is how it is done using a Table Template:
Code:
class MY_Controller extends CI_Controller {

/**
  * -----------------------------------------------------------------------
  * Class variables - public, private, protected and static.
  * -----------------------------------------------------------------------
  */


  // ----------------------------------------------------------------------

/**
  *  __construct
  *
  * Class Constructor PHP 5+
  *
  * @author Raymond King Sr.
  * @access public
  * @return void
  */
  public function __construct()
  {
   parent::__construct();

  $this->load->library('table');

  $tmpl = array (
   'table_open'   => '<table border="0" cellpadding="4" cellspacing="0">',

   'thead_open'   => '<thead>',
   'thead_close'   => '</thead>',

   'heading_row_start'  => '<tr>',
   'heading_row_end'  => '</tr>',
   'heading_cell_start' => '<th>',
   'heading_cell_end'  => '</th>',

   'tbody_open'   => '<tbody>',
   'tbody_close'   => '</tbody>',

   'row_start'    => '<tr>',
   'row_end'    => '</tr>',
   'cell_start'   => '<td>',
   'cell_end'    => '</td>',

   'row_alt_start'   => '<tr class="alt">',
   'row_alt_end'   => '</tr>',
   'cell_alt_start'  => '<td>',
   'cell_alt_end'   => '</td>',

   'table_close'   => '</table>'
  );

  $this->table->set_template($tmpl);
}

}

Now you can use add_row etc and build your table using a foreach loop on your query from the database.

In your view were you want the table generated just add this:
Code:
&lt;?php echo $this->table->generate(); ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB