Welcome Guest, Not a member yet? Register   Sign In
Problem with function list_fields()
#1

[eluser]Atas[/eluser]
Hello, the function "list_fields" in mysql_results.php (line 63) doesn't return any data.

I am trying to export csv data from a sql result.

Code:
$query = $this->db->query("SELECT * FROM table);                      

$delimiter = ",";
$newline = "\n";            

$content = $this->dbutil->csv_from_result($query, $delimiter, $newline);


The function csv_from_result calls "list_fields" to generate the headings from the table column names.

I am working in CI 1.7.0.

Any ideas ?

Sorry my english...
#2

[eluser]pistolPete[/eluser]
Do you get an error message?

Code:
$query = $this->db->query("SELECT * FROM table);
You omitted a double quote, is this just a typo ?

Is your table really called "table" ?
Did you setup your database correctly?

Please post more code...
#3

[eluser]Atas[/eluser]
Hello pistolPete, I posted that query for reference only, the original query works fine.

e.g.
$query = $this->db->query("SELECT * FROM user WHERE use_active = 1");

$delimiter = ",";
$newline = "\n";

$content = $this->dbutil->csv_from_result($query, $delimiter, $newline);

If I make an echo of $content I get the data without the headings.
#4

[eluser]gr0uch0mars[/eluser]
Hi! I'm also having headaches with list_fields().

My case is: I'm organising the language strings in a database, then I create a script to write the _lang.php files to use with the language class.

The structure of my table is: one column for string names (column "string"), one column per language (column name is language name: 'english', 'spanish'...). Then, each row is a string, with its translations into all languages.

The problem comes when I try to create a controller to update the language files in my language folders (writing the php file with a script) from the database. I list fields (to retrieve all column names, that is, all languages) and then, foreach language , I write the .php file.

This is my code:

Code:
$fields = $this->db->list_fields('languages'); // Retrieve all languages (table columns, including the first one "string")
foreach ($fields as $field)
{
   $data = "<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
"; // The begining of the _lang.php file

   $this->db->select("string, $field"); // $field means 'spanish', 'english', etc.
   $strings = $this->Languages->get_language_strings();
   foreach ($strings->result_array() as $string)
   {
      $data .= '$lang["'.$string['string'].'"] = "'.$string[$field].'"; // $string[$field], there comes the problem.
';
   }

   $data .= "?>"; // End of _lang.php file

   // I start writing the _lang.php file
   if ( ! write_file('./system/application/language/'.$field.'/'.$field.'_lang.php', $data))
   {
      echo '<p>Unable to write the file</p>';
   }
   else
   {
      echo '<p>File written!</p>';
   }
}

PROBLEM 1: When I write the line
Code:
$lang['logout'] = 'Log Out';
I don't know how to tell the script that 'Log Out' belongs to column $field.

When I write this code
Code:
$data .= '$lang["'.$string['string'].'"] = "'.$string[$field].'";
(and I'm using arrays exceptionally because I don't know what more to do) you see
Code:
$string[$field]
That means that $field corresponds to 'english, spanish, etc.', one per column (that's why I use a list_field foreach at the beginning). Using objects ($string->$field) doesn't work neither, so what can I do???

PROBLEM 2 (minor problem): How to do a foreach ignoring the first column "string" (which has only the string names, not any translation).

I know my explanation is awful Smile , but I think you can help me. If you don't understand something, just ask me.

Thank you!




Theme © iAndrew 2016 - Forum software by © MyBB