Jump to content

wrap SQL output


elite311

Recommended Posts

Hi,

I'm trying to build my own news system with PHP and SQL, I have everything working but I'm completely stuck on one element. I have created a DIV container for the SQL output to show in however the SQL output just goes right through the DIV and doesn't wrap the output.

 

Here is my code:

 

<?php
include('config.php');

$db = new Database($db_host, $db_username, $db_password, $db_database, $db_table_prefix);
$db -> connect();

$result = $db->fetch_all_array("SELECT * FROM news ORDER BY id ASC");
?>

 

<div id="news">
   <?php foreach($result as $option) { ?>
        <div class="news-heading"><?php echo $option['newshesding'];?></div>
        <div class="news-text"><?php echo $option['newstext'];?></div>
   <?php } ?>
</div>

 

I have used this code to make it wrap and it does what I want by wraping after 10 characters.

 

<div class="news-text"><?php echo wordwrap($option['newstext'], 100, "\n", true);?></div>

 

However I'm trying to figure out how to do this with the DIV itself, because on a smaller device like my iPhone using the above code doesn't diplay properly as the text runs right to the edge of the screen.

 

My CSS looks like this:

 

#news .news-text{
padding-bottom:15px;
white-space:pre;
padding-left:5px;
padding-top:5px;
}

 

If anyone can help I'd appreciate it, thanks.

Link to comment
https://forums.phpfreaks.com/topic/254559-wrap-sql-output/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.