hi,
I wonder if jquery or javascript has the function adding line breaks which can be similar to nl2br() in PHP?
This is the info i want to grab from a database, PHP will add line breaks (<br/>) when it is passed into nl2br(),
Code:
<?php echo nl2br($row_cover['img_info']);?>
[HTML]Blue Bar
2007
Acrylic and digital print on canvas in carved wood, coconut, mother of pearl and coin inlaid artist frame
72 x 86 x 7 in. (182.9 x 218.4 x 17.8 cm)
Courtesy Lehmann Maupin Gallery, New York and Jay Jopling, White Cube, London [/HTML]
PHP Code:
<?php
if(empty($pg_id))
{
$img_id = $_REQUEST['img_id'];
include('../incl_corefuncs/conn_mysql.inc.php');
include('../incl_corefuncs/core.php');
}
?>
<?php
$sql_cover = "
SELECT *,
UNIX_TIMESTAMP( img_created ) AS img_created
FROM root_images
WHERE root_images.pg_id = '$pg_id'
OR root_images.img_id = '$img_id'
";
//
$result_cover = mysql_query($sql_cover);
$row_cover = mysql_fetch_assoc($result_cover);
?>
<!--cover-->
<div class="cover">
<a href="#"><img src="<?php echo $row_cover['img_path_large'];?>" alt="<?php echo $row_cover['img_name'];?>"/></a>
</div>
<!--cover-->
<div class="info">
<?php echo nl2br($row_cover['img_info']);?>
</div>
<?php
$sql_preview = "
SELECT *,
UNIX_TIMESTAMP( img_created ) AS img_created
FROM root_images
WHERE root_images.pg_id = '$pg_id'
";
//
$result_preview = mysql_query($sql_preview);
?>
<!--preview-->
<div class="preview">
<ul>
<?php
while($row_preview = mysql_fetch_assoc($result_preview))
{
list($width, $height, $type, $attr) = getimagesize($row_preview['img_path_large']);
?>
<li><a href="<?php echo $row_preview['img_id'];?>" onclick="loadImage('<?php echo $row_preview['img_id'];?>',<?php echo $height;?>); return false;"><img src="<?php echo $row_preview['img_path_small'];?>" alt="<?php echo $row_preview['img_name'];?>" longdesc="<?php echo $row_preview['img_info'];?>"/></a></li>
<?php
}
?>
</ul>
</div>
<!--preview-->
the trouble is, i can grab the data and put it in the div with jquery, but i dont know how to add line breaks in the data... this is the code,
Code:
<script type="text/javascript" language="javascript">
// <![CDATA[
$(document).ready(function(){
$("#imagepreview li:first").addClass("currentimage");
});
// remove all classes
function removeClassAll() {
$("#imagepreview li").removeClass("currentimage");
}
// load content with ajax and add a class
function loadImage(img_id, height) {
$("#imagepreview li").click(function () {
removeClassAll();
$(this).addClass("currentimage");
var $this = $(this);
var info = $this.find('img').attr("longdesc");
$(".info").text(info);
});
$("#imagecover").fadeOut('fast', function(){
$("#imagecover").html('<div class="ajaxloader"><p><img src="img_iconies/loader_0.gif"/> loading...</p></div>');
});
$("#imagecover").animate({height:height}, 500, function(){
$("#imagecover").load( "incl_layouts.global/item.projects.images.cover.php?img_id=" + img_id, {}, function(){ //calling the ajax then with a callback afterwards
$("#imagecover").css({display:'none'})
.fadeIn("slow");
});
});
}
// ]]>
</script>
thanks if u can help.
Lau