Welcome Guest, Not a member yet? Register   Sign In
database syntax error help please
#1

[eluser]Miguel Diaz[/eluser]
I am trying to make a left join in a database with a group_concat to add categories to a blog I am making but It is sending me an error.

This is my model

Code:
function cargarNoticias(){
        $data = array();
        $q = $this->db->query("    SELECT
            a.articuloTitulo as 'articuloTitulo',
            a.articuloDescripcion as 'articuloDescripcion',
            a.articuloFecha as 'articuloFecha',
            a.articuloHora as 'articuloHora',
            a.articuloID as'articuloID',
             GROUP_CONCAT(CONCAT('<a>', ca.categoriaNombre, '</a>')) as categorias ,
            count(c.comentarioID) as Comentarios
            FROM articulos a
            LEFT JOIN categorias_articulos ca ON ca.articuloID=a.articuloID
            LEFT JOIN categorias cat ON a.articuloID=cat.categoriaID
            LEFT JOIN comentarios c ON a.articuloID=c.articuloID
            GROUP BY a.articuloID
            desc
        ");
        if($q->num_rows() > 0) {
            foreach($q->result() as $row){
                $data[] = $row;
            }
            $q->free_result();      
        }
        return $data;
    }

this model works great but when I am trying to put the href inside the anchor with the two"" it send me a syntax error.

Please can someone help me I am new with databases and I cant see why
#2

[eluser]toopay[/eluser]
Code:
//If you want to put double quote within double quote like above, escape it with backslash \"
// i escaped anchor tag 'a' to '\a' just to give an ilustration, because you can't write anchor tag on CI Forum
....
GROUP_CONCAT(CONCAT('<\a href=\"some_link\">', ca.categoriaNombre, '</a>')) as categorias ,
....
#3

[eluser]Miguel Diaz[/eluser]
Thanks toopay I really apprecciate your help

This works perfect
#4

[eluser]Miguel Diaz[/eluser]
One more question toopay I am trying also to put after the link another ca.categoriaNombre to send it to that category. How should I do that if i already put the escape witht the backslash.

I tried this but didnt work.
Code:
GROUP_CONCAT(CONCAT('</a href=\"link\', LOWER(ca.categoriaNombre), '">', ca.categoriaNombre, '</a>')) as categorias ,
#5

[eluser]toopay[/eluser]
Code:
GROUP_CONCAT(CONCAT('</a href=\"link/', LOWER(ca.categoriaNombre), '\">', ca.categoriaNombre, '</a>')) as categorias ,




Theme © iAndrew 2016 - Forum software by © MyBB