Rifts Posted November 9, 2010 Share Posted November 9, 2010 ok what in the world is going on here... I have a simple javascript code to switch out the text between a div there are 4 rotations the text that is being switched is populated from my DB using php. now the weird part. in my DB i'm using longtext now If the text in the db is all one paragraph everything works fine but if there is any type of line break or new paragraph the script wont rotate at all. any ideas? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 9, 2010 Share Posted November 9, 2010 the line breaks are probably hosing the Javascript. Do you get any JS errors in the browser? Can you post the JS portion of the HTML output so we can see it? Quote Link to comment Share on other sites More sharing options...
Rifts Posted November 9, 2010 Author Share Posted November 9, 2010 No no errors at all. here is the code.. so yeah if i change ANY of the 4 text fields and add a break at all it just doesn't rotate. <? include 'dbconfig.php'; $result = mysql_query(" SELECT * FROM featured where active='2' "); while($row = mysql_fetch_array($result)) { $text2 = $row['text']; $img2 = $row['image']; } $result = mysql_query(" SELECT * FROM featured where active='3' "); while($row = mysql_fetch_array($result)) { $text3 = $row['text']; $img3 = $row['image']; } $result = mysql_query(" SELECT * FROM featured where active='4' "); while($row = mysql_fetch_array($result)) { $text4 = $row['text']; $img4 = $row['image']; } $result = mysql_query(" SELECT * FROM featured where active='1' "); while($row = mysql_fetch_array($result)) { $text1 = $row['text']; $img1 = $row['image']; } ?> <script type="text/javascript"> var test=new Array(); test[0]='<?= $text2; ?>'; test[1]='<?= $text3; ?>'; test[2]='<?= $text4; ?>'; test[3]='<?= $text1; ?>'; var speed=5000; var q=0; function showQuote() { document.getElementById("tests").innerHTML=test[q]; q++; if(q==test.length) { q=0; } } setInterval('showQuote()',speed); </script> for example if i change one of the text fields from hello, welcome to my site to hello, welcome to my site it breaks it Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 9, 2010 Share Posted November 9, 2010 Have you tried using nl2br() to convert line breaks to HTML line break tags? Quote Link to comment Share on other sites More sharing options...
Rifts Posted November 9, 2010 Author Share Posted November 9, 2010 yeah that was the first thing i tried =] Quote Link to comment Share on other sites More sharing options...
Rifts Posted November 9, 2010 Author Share Posted November 9, 2010 well i think i figured it out using $str = str_replace(array("\r\n", "\r", "\n"), "<br />", $text2); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.