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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.