Log in

View Full Version : RTE preloaded html content as a variable with php



lolo
01-14-2007, 06:30 PM
Hi there,

I am trying to change the preload html content, and use the content of a variable instead. When I declare the variable in the page it works :

<?php
$test="<b>hello</b> world";
?>
<script language="JavaScript" type="text/javascript">
<!--
writeRichText('rte1', '<?php echo $test;?>', 520, 400, true, false);

this works fine, the RTE shows : hello world , in the text box

but if my content comes from my MySql data base :

<?php
$sql = "SELECT test FROM test";
$req=mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error());
$data=mysql_fetch_assoc($req);
$test=$data['test']; //this contains "<b>hello</b> world"
?>
<script language="JavaScript" type="text/javascript">
<!--
writeRichText('rte1', '<?php echo $test;?>', 520, 400, true, false);
//-->
</script>

the RTE doesn't even open.

What do I do wrong? Can someone help?
thank you :)
lolo

thetestingsite
01-14-2007, 06:37 PM
It may be something with the SQL query. Try simply echoing $test outside of the RTE and see if it echos. If not, you may need to change the mysql_fetch_assoc to mysql_fetch_array or something like that.

Hope this helps.

lolo
01-14-2007, 08:08 PM
The problem comes from mysql and the fact that the RTE actually adds some &#37;0D%0A at the end of the rte1 variable value. Means that is works if I manually enter the html code in my database, but if I use INSERT and $_GET['rte1'] to fill my database there are 2 extra blank line that are the cause of the problem (I think), and when I echo it with php these 2 line don't show.
Someone knows how I can get rid of these %0D%0A before filling the db?

lolo

(thanks testing site)

Twey
01-14-2007, 08:42 PM
Please don't cross-post. (http://www.dynamicdrive.com/forums/showthread.php?p=69346)

I've answered in that thread; had I seen this one first, I would have answered here, since it is more appropriate.

lolo
01-14-2007, 09:18 PM
perfect , sorry for the cross post

lolo
01-14-2007, 09:37 PM
thanx again master!