⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Error while trying to display data from a table



reynierpm
  • profile picture
  • Member

Posted 13 April 2012 - 00:32 AM

Hi, I'm trying to get Grocery CRUD working on a site I'm developing but can't get. As the docs said I do this:
1) Load the library at __construct() function as follow:

function __construct() {
parent::__construct();
$this->load->library('grocery_CRUD');
}

2) Try the code at examples.php but modified to suit my needs:

public function search() {
try {
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('tr007_usuarios');
$crud->set_subject('Propietarios');
$crud->columns('codigo', 'cedula', 'nb_usuario');

$output = $crud->render();
} catch (Exception $e) {
show_error($e->getMessage() . ' --- ' . $e->getTraceAsString());
}

$this->load->view('users/search', $output);
}

3) Print the $output at the template

echo $output;

But get this error
[quote]

[b] A Database Error Occurred[/b]

Error Number:
ERROR: syntax error at or near "FROM" LINE 1: SHOW COLUMNS FROM tr007_usuarios ^
SHOW COLUMNS FROM tr007_usuarios
Filename: /var/www/html/sic-auto-gas/models/grocery_crud_model.php
Line Number: 302
[/quote]

Any help?

reynierpm
  • profile picture
  • Member

Posted 13 April 2012 - 01:48 AM

Ok, after do some research and my bad because I must search before post :( I found this thread /topic/50-postgresql-and-grocery-crud/. Right now I'm trying to implement the [font=monospace]"[/font]function get_field_types_basic_table(){}" for PostgreSQL but need some help in order to understand what the stuff inside this function means. As said here http://www.postgresql.org/docs/current/static/infoschema-columns.html, Postgres have a totally different way to get information about tables and columns so the query is this one:
$this->db->query("SELECT columns FROM information_schema.COLUMNS WHERE table_name = '{$this->table_name}'")->result()

But what this means:

$db_field_types[$db_field_type->Field]['db_max_length'] = $length; // db_max_length related to what? column? In postgres this is different dependent on column type, see character_maximum_length and numeric_precision
$db_field_types[$db_field_type->Field]['db_type'] = $db_field_type->data_type;
$db_field_types[$db_field_type->Field]['db_null'] = $db_field_type->is_nullable == 'YES' ? true : false;
$db_field_types[$db_field_type->Field]['db_extra'] = $db_field_type->Extra; // what is that and what is used for

Hope someone help me to understand this in order to end the function and share to community ;)
Cheers