C
C
Carry2015-10-09 12:34:12
PHP
Carry, 2015-10-09 12:34:12

How to change the field names for output from the database by condition?

Tell

try {
            $this->db_iniciate_connect();
            $this->generateSearchString($filters);

            $rs = $this->db->query($this->strSql);
            $suggestions = array();
            while($row = $rs->fetch_assoc())
            {
                $suggestions[] = array
                (
                'id' => $row['id'],
                'frm' => $row['frm']
                );
            }
            echo json_encode(array('rows' => $suggestions));
        }

I need to change the number of fields and the names of the fields depending on the conditions... What is the best way to implement this. I want to make one template for all tables. Those. if this is a different table and there will be other fields for output, respectively.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Smirnov, 2015-10-09
@carryx

- $suggestions[] = array
- (
- 'id' => $row['id'],
- 'frm' => $row['frm']
- );
+ $suggestions[] = $row;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question