Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

display a data with smarty is not correct
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
ahoussam
Smarty Rookie


Joined: 26 Jan 2010
Posts: 16

PostPosted: Tue Mar 16, 2010 9:36 am    Post subject: display a data with smarty is not correct Reply with quote

hello
I used query to get data from oracle, i used tow method to display this data such as:
Code:
$nrows = oci_fetch_all($stid, $data_res, null, null, OCI_FETCHSTATEMENT_BY_ROW);

first with php file:
Code:

foreach ($data_res as $col) {
    echo "<tr>\n";
    foreach ($col as $item) {
        echo "    <td>".($item !== null ? htmlspecialchars($item, ENT_QUOTES) : "&nbsp;")."</td>\n";
    }
    echo "</tr>\n";
}

I got correct data display
second with smarty file, I am passing data to the mStudent variable:
Code:

{section name=i start=0 loop=$mStudent}
    <tr>
    <td>{$mStudent[i].id}</td>
    <td>{$mStudent[i].first_name}</td>
    <td>{$mStudent[i].second_name}</td>
    <td>{$mStudent[i].email}</td>   
    <td>{$mStudent[i].NOTE}</td>     
    </tr>

data characters appear in an illegible such as :
I use utf8 charset
When I used escape like ($mStudent[i].first_name|escape) the data disappear
when i used escape like ($mStudent[i].first_name|escape:'htmlall') the data display as Incomprehensible char such as:
can any one resolve this problem?
thanks
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7364
Location: Lincoln Nebraska, USA

PostPosted: Tue Mar 16, 2010 2:36 pm    Post subject: Reply with quote

Smarty 2 or 3? Do you have multibyte support installed in PHP?
Back to top
View user's profile Send private message Visit poster's website
ahoussam
Smarty Rookie


Joined: 26 Jan 2010
Posts: 16

PostPosted: Wed Mar 17, 2010 8:11 am    Post subject: Reply with quote

thanks
I use Smarty v2.6.9 and php version 5.2.8
Multibyte Support : enabled
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7364
Location: Lincoln Nebraska, USA

PostPosted: Wed Mar 17, 2010 12:55 pm    Post subject: Reply with quote

Try the latest smarty release first, 2.6.9 is quite old.
Back to top
View user's profile Send private message Visit poster's website
ahoussam
Smarty Rookie


Joined: 26 Jan 2010
Posts: 16

PostPosted: Wed Mar 17, 2010 2:33 pm    Post subject: Reply with quote

a same result!

thanks
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7364
Location: Lincoln Nebraska, USA

PostPosted: Wed Mar 17, 2010 2:36 pm    Post subject: Reply with quote

So you are saying in PHP:

Code:
echo $myvar;


shows correctly, and if you do:

Code:
$smarty->assign('myvar',$myvar');


Code:
{$myvar}


I does not display right? Can you do this quick test?
Back to top
View user's profile Send private message Visit poster's website
SoN9ne
Smarty Rookie


Joined: 25 Feb 2010
Posts: 17

PostPosted: Wed Mar 17, 2010 11:36 pm    Post subject: Reply with quote

What is your database collation?
Did you setup a new database and inject data from an older one into it?

I have seem this a few times and it was due to a database with a different encoding (latin_swedish_1) being injected into a new database with a utf-8 collation.
Back to top
View user's profile Send private message
ahoussam
Smarty Rookie


Joined: 26 Jan 2010
Posts: 16

PostPosted: Thu Mar 18, 2010 7:32 am    Post subject: Reply with quote

thank you very much
yes I'm sure, without smarty i got this result:

I have discovered something new, when I change the encoding in your browser to Arabic (Windows) shows the data are correct, while everything else in the page (wrote with arabic) appears incorrectly such as this image:


in smarty file i use utf8, and database utf8
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7364
Location: Lincoln Nebraska, USA

PostPosted: Thu Mar 18, 2010 1:20 pm    Post subject: Reply with quote

Do you have a meta tag in the browser that sets the charset you want?
Back to top
View user's profile Send private message Visit poster's website
ahoussam
Smarty Rookie


Joined: 26 Jan 2010
Posts: 16

PostPosted: Thu Mar 18, 2010 1:24 pm    Post subject: Reply with quote

yes i have it, i use two: Internet explorer and firefox
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7364
Location: Lincoln Nebraska, USA

PostPosted: Thu Mar 18, 2010 1:26 pm    Post subject: Reply with quote

If you switch the encoding to Arabic and it looks right, that makes me think the charset is not UTF8, but Arabic. Are you setting the charset to Arabic in the meta tag?
Back to top
View user's profile Send private message Visit poster's website
ahoussam
Smarty Rookie


Joined: 26 Jan 2010
Posts: 16

PostPosted: Thu Mar 18, 2010 1:37 pm    Post subject: Reply with quote

no, my browser auto-select lanaguage, but i try to select arabic/utf-8 to view data is correct (manual)!
and i save my file as : unix|utf-8
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7364
Location: Lincoln Nebraska, USA

PostPosted: Thu Mar 18, 2010 1:51 pm    Post subject: Reply with quote

does the text look right if you take Smarty out of the picture and just display straight from PHP? My guess is Smarty is not causing any of this.
Back to top
View user's profile Send private message Visit poster's website
ahoussam
Smarty Rookie


Joined: 26 Jan 2010
Posts: 16

PostPosted: Thu Mar 18, 2010 1:57 pm    Post subject: Reply with quote

Completely, with PHP appear correctly, as in the previous image!
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7364
Location: Lincoln Nebraska, USA

PostPosted: Thu Mar 18, 2010 2:58 pm    Post subject: Reply with quote

So as in my test above:

Code:
echo $myvar;


shows correctly?

And then:

Code:
$smarty->assign('myvar',$myvar');


Code:
{$myvar}


Does not show correctly? It should since Smarty does nothing to the text and just echos it, much the same as PHP.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP