Web Analytics Made Easy -
StatCounter mysql_fetch_assoc() text won't wrap - CodingForum

Announcement

Collapse
No announcement yet.

mysql_fetch_assoc() text won't wrap

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resolved mysql_fetch_assoc() text won't wrap

    This is a little strange. I am pulling data from a table that contains articles and trying to display a date from the table along with a short description.
    Sounds simple right?
    While the data is pulling from the DB just fine, when I display the result on the page, the short description won't wrap inside the <td> where the data is placed.

    Here is the code I am using to display:
    PHP Code:
    while ($row mysql_fetch_assoc($result)){
        print 
    "<h1 class=\"news\">".date("F jS, Y"strtotime($row["DateSummarized"]))."</strong><br>";
        print 
    "<p class=\"news\">".$row['ShortDescrip']."</p><br/>";
        } 
    The field "ShortDescrip" is listed in the table like this:

    Field: ShortDescrip
    Type: varchar(180)

    Now I just assumed (apparently incorrectly) that the text would wrap. I've tried limiting the width through CSS and even applying a width value directly to the <TD>.

    Any ideas?
    Last edited by thepocketgeek; Apr 8, 2009, 10:07 AM.

  • #2
    Any chance seeing your CSS and HTML? Would need a lot more information to see whats going on. But I can assure you it isn't a PHP issue it's an HTML/CSS issue. By the time its echoed to your browser text is text. It's a little confusing because you have an open <h1> tag which isn't closed and a closing </strong> tag which isn't opened.

    In the mean time validator.w3.org may help
    Last edited by timgolding; Apr 7, 2009, 07:10 PM.
    You can not say you know how to do something, until you can teach it to someone else.

    Comment


    • #3
      Thanks for taking the time to reply. Here is a test page I have created to illustrate the problem I am having.

      http://dev.snfcb.com/test.php

      Here is the code on the test page:

      Code:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Untitled Document</title>
      <style type="text/css">
      	h1.news {
      		font-family: Arial, Helvetica, sans-serif;
      		font-size: 14px;
      		font-weight: bold;
      		color: #666666;
      		}
      	
      	p.news {
      		font-family: Arial, Helvetica, sans-serif;
      		font-size: 12px;
      		color: #666666;
      		}
      		
      	.redLL {
      		color: #910101;
      	}
      </style></head>
      
      <body>
      
      <div style="width: 150px; background-color:#CCCCCC;">
      <?php include('includes/news.php') ?>
      </div>
      
      </body>
      </html>
      Here is the code from the script that is called in the above code:

      PHP Code:
      <?php 
      include('DB-CONNECT-SCRIPT-NAME');

      $sql        "SELECT ID, DateSummarized, ShortDescrip FROM news ORDER BY ID DESC LIMIT 5";
      $result        mysql_query($sql);

      print 
      "<pre>";
      print_r($row);

      print 
      "<h1 align=\"left\" class=\"redLL\">News & Events</h1><br>";

      while (
      $row mysql_fetch_assoc($result)){
          print 
      "<h1 class=\"news\">".date("F jS, Y"strtotime($row["DateSummarized"]))."</h1><br>";
          print 
      "<p class=\"news\">".$row['ShortDescrip']."</p><br/>";
          }

      ?>
      Last edited by thepocketgeek; Apr 8, 2009, 09:48 AM.

      Comment


      • #4
        UGH!
        Nevermind. I saw it once I looked at what was outputting to the browser. Thanks for the Validation tip. I still had a couple of print statements in there that I was using to test the Query.

        I took them out and it works like a charm now.

        Comment

        Working...
        X