Welcome Guest, Not a member yet? Register   Sign In
Problem with a db query
#1

[eluser]Unknown[/eluser]
I have a problem with one query.

I have this code:

Code:
$this->db->select("f.*, (SELECT GROUP_CONCAT (CONCAT(p.nome, ' ', p.cognome) SEPARATOR ', ')
                         FROM professionisti p
                                                 WHERE p.id IN (SELECT r.id_professionista FROM registi r WHERE r.id_film = f.id)
                                                ) AS regista", FALSE);
$this->db->from($this->tables['film'] . ' f');
$this->db->where("f.pagina_html = '" . $film . "'");
$sql = $this->db->get();
return $sql->row();

but the above code return me the following error:

Quote:An Error Was Encountered

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SEPARATOR ', ') FROM professionisti p ' at line 1

SELECT f.*, (SELECT GROUP_CONCAT (CONCAT(p.nome, ' ', p.cognome) SEPARATOR ', ') FROM professionisti p WHERE p.id IN (SELECT r.id_professionista FROM registi r WHERE r.id_film = f.id) ) AS regista FROM (`film` f) WHERE f.pagina_html = 'grindhouse_us_version'

the query reported in the error message don't have problem in phpmyadmin.

I also tried with the following code:

Code:
$sql = "SELECT f.*, (SELECT GROUP_CONCAT (CONCAT(p.nome, ' ', p.cognome) SEPARATOR ', ')
FROM professionisti p
WHERE p.id IN (SELECT r.id_professionista FROM registi r WHERE r.id_film = f.id)
) AS regista
FROM film f
WHERE f.pagina_html = '" . $film . "'";
$query = $this->db->query($sql);

but return me the same error.

Where is the problem?


PS: excuse me for my english. I hope you can understand what i wrote.
#2

[eluser]Unknown[/eluser]
Ok, i have found the solution.

The problem was the blank space between "GROUP_CONCAT" and "(". When i leave that space it's ok.




Theme © iAndrew 2016 - Forum software by © MyBB