Welcome Guest, Not a member yet? Register   Sign In
avoid escape $this->db->get();
#1

[eluser]luca89pe[/eluser]
Hi,
i have a database with products. It contains: photo, name and a description of each product.
I need to print that in a view, i got results with:
Code:
$this->db->get("mytable");
But in description i need some newlines:
Code:
for example:
code: 003810391849.

product description
I put a
Code:
<br />
in the description field, after "code: 003810391849." but it doesn't work: codeigniter escapes it and print code:
Code:
003810391849.<br /> product description
There is a way to put there a newline?

Thank You,
Luca
#2

[eluser]TheFuzzy0ne[/eluser]
I don't quite understand what you mean. I've never had this problem myself.

Please post your view, and we can take it from there.
#3

[eluser]luca89pe[/eluser]
Thank you for reply, i'll post all.

I have a field in mysql table like this:
Code:
codice BEG001T90F800
<br />
Tomaia in pizzo nero applicato su raso rosso boredeaux,
con bordini in vernice nera e applicazione in swarowsky.
puntina, laterali e cinturino in vernice nera.
sottopiede antishock, suola in cuoio morbido
tacco laccato nero lucido, altezza 90 mm
<br /><br />
è in via di realizzazione anche la versione pizzo nero su raso rosa.
Than, i have this controller to extract data for that table (table name is "donna"):
Code:
&lt;?php

// creazione di un semplice controller
class Donna extends CI_Controller{

    function index(){
        $query = $this->db->get("donna");
        $data['collezione'] = $query->result();
        $data['page_content'] = $this->load->view("donna",$data, true);
        $this->load->view("template", $data);
    }

}

?&gt;
And, finally, this is the view:
Code:
<section id="productShow">
    <article id="productPhoto" class="dp60"  right;">
        <img id="img_01" class="imgsmall" src="&lt;?php echo $collezione[0]-&gt;immagine; ?&gt;" data-zoom-image="&lt;?php echo $collezione[0]-&gt;zoom; ?&gt;" />
    </article>
    <article id="productDesc" class="dp40">
        <div id="prodName" class="dp100 textCenter">&lt;?php echo $collezione[0]->nome; ?&gt;</div>
        <div id="prodDesc" class="dp100"><br />&lt;?php echo $collezione[0]->descrizione; ?&gt;</div>
        <div class="clear"></div>
    </article>
    <div class="clear"></div>
</section> &lt;!-- #content--&gt;

[....... obmitted ..........]

[removed]
    $(document).ready(function() {
        $("#img_01").elevateZoom({gallery:'carousel', cursor: 'pointer', galleryActiveClass: 'active',   zoomType: "inner",});
        //pass the images to Fancybox
        $("#img_01").bind("click", function(e){
            var ez = $('#img_01').data('elevateZoom');
            $.fancybox(ez.getGalleryList());
            return false;
        });
    $("#carousel li a").click(function(){
        $("#prodName").text($(this).attr("data-nome"));
        $("#prodDesc").text($(this).attr("data-descrizione"));
});

});
[removed]

Now, i want it prints obmitting the BR tag, and translate it with a newline:
Code:
codice BEG001T90F800

Tomaia in pizzo nero applicato su raso rosso boredeaux,
con bordini in vernice nera e applicazione in swarowsky.
puntina, laterali e cinturino in vernice nera.
sottopiede antishock, suola in cuoio morbido
tacco laccato nero lucido, altezza 90 mm


è in via di realizzazione anche la versione pizzo nero su raso rosa.
but it prints it showing the BR tag, and without the newline:
Code:
codice BEG001T90F800
<br />
Tomaia in pizzo nero applicato su raso rosso boredeaux,
con bordini in vernice nera e applicazione in swarowsky.
puntina, laterali e cinturino in vernice nera.
sottopiede antishock, suola in cuoio morbido
tacco laccato nero lucido, altezza 90 mm
<br /><br />
è in via di realizzazione anche la versione pizzo nero su raso rosa.


Thank you,
Luca
#4

[eluser]luca89pe[/eluser]
bump... no one can help me?!?! Sad

thank you,
Luca
#5

[eluser]Herlevsen[/eluser]
You need to use the html entities for the tags. have a look here http://www.w3schools.com/html/html_entities.asp.

Best practice would be to store it with the html entities in your database if thats always how you want to output it, IMO. But you could also do it on output by using either htmlspecialchars or htmlentites.
http://php.net/manual/en/function.htmlentities.php
http://php.net/manual/en/function.htmlspecialchars.php
#6

[eluser]TheFuzzy0ne[/eluser]
Where in your view does this problem occur? Is it when you echo $collezione[0]->descrizione?

It looks to be like the output is being escaped, but I don't understand where. From what I can see, you're just echoing the output, it's not actually being passed through any CodeIgniter functions.
#7

[eluser]Herlevsen[/eluser]
I must have been very tired when i wrote my reply. I see now that you dont want to output the <br>, but just want a new line, when i thought it was the opposite (which seemed pretty strange).

It is your jquery that escapes it, when you use the text method

Code:
$("#prodName").text($(this).attr("data-nome"));
http://api.jquery.com/text/

Instead you need to use the html method
http://api.jquery.com/html/
#8

[eluser]luca89pe[/eluser]
[quote author="Herlevsen" date="1369388001"]I must have been very tired when i wrote my reply. I see now that you dont want to output the <br>, but just want a new line, when i thought it was the opposite (which seemed pretty strange).

It is your jquery that escapes it, when you use the text method

Code:
$("#prodName").text($(this).attr("data-nome"));
http://api.jquery.com/text/

Instead you need to use the html method
http://api.jquery.com/html/[/quote]

omg, that's all! thank you!!!! i tought codeigniter was the one that escaped the text, instead of jquery!

Thank's to TheFuzzy0ne too, but Herlevsen centered the problem!!!!!!!

Thank you guys!!! Smile
#9

[eluser]Pert[/eluser]
Or you can always use typeography helper and not save html code in database at all:

http://ellislab.com/codeigniter/user-gui...elper.html




Theme © iAndrew 2016 - Forum software by © MyBB