Solved

PHP Formating in Dreamweaver

Posted on 2006-11-05
6
335 Views
Last Modified: 2006-11-18
Hi Experts,

I have to questions.  I have a web based MySQL table that is used to display news on a php webpage.

I have 2 problems.  One is how do i re-format the time stamp from 20061001 (YYYYMMDD) to Oct 1, 2006.  I have tried to reformat the timestamp in the sql query that retrives the information and also using dreamweavers date formating, the end result remains the same, when the timestamp says 20061001 the page displays Jan 1, 1970.

My second problem is formating text from a longtext field.  When i set the text formating to paragraph, the line breaks are not show. When i set the formating to preformatted the line breaks appear, but the text doesn't continue to the next line when it reaches the width limit of the page, it actually ignores the limit and the page extends until the line ends.  Should i be formating this at the query level?  If so how?
0
Comment
Question by:andrewl77
  • 4
  • 2
6 Comments
 
LVL 35

Expert Comment

by:Raynard7
ID: 17877570
Hi,

Question 1 - you could format this with php or with mysql
DATE_FORMAT(fieldName, '%b %e, %Y');

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

or using the date function in php http://au3.php.net/date

for the second option the reason that new lines do not appear is that html does not recognise them - you would need to repalce the new line characters with <br /> - which I would reccomend that you do with php - on saving the data into your database, rather than on retreival
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17877575
in php if your text was $bodyText

to isert line breaks you could do

$bodyText = str_replace("\r", "<br />", str_replace("\n", "", $bodyText));
http://au3.php.net/manual/en/function.str-replace.php
0
 

Author Comment

by:andrewl77
ID: 17877605
Thanks Raynard7.

Working on the date formating now.

<?php echo $row_PMAppointments['date']; ?> this is what is existing.

Should i be changing it to look like this:

<?php echo DATE_FORMAT($row_PMAppointments['date'], '%b %e, %Y'); ?>

or

<?php echo $row_PMAppointments(DATE_FORMAT(['date'], '%b %e, %Y')); ?>

I tested both these and it drops the field all together.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 35

Expert Comment

by:Raynard7
ID: 17877613
no,

The option that I gave was to put these into your query,

so previously you had a field called 'date' in your query

now in your query use where you previously had the field called date

DATE_FORMAT(`date`, '%b %e, %Y') as date1

(do not use date for a date field, gets very confusing as many programs have functions called date)

so now all you need to do

<?php echo $row_PMAppointments['date1']; ?>
0
 

Author Comment

by:andrewl77
ID: 17877672
Have got the date to work a treat, thanks for that, not sure on the text formating.  I am inserting the text from a dreamweaver php form.

This is the script that inserts the record:

$insertSQL = sprintf("INSERT INTO coaches (subject, textbody, postedby, `section`) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['subject'], "text"),
                       GetSQLValueString($_POST['newsbody'], "text"),<= This is the text body
                       GetSQLValueString($_POST['postby'], "text"),
                       GetSQLValueString($_POST['umptype'], "text"));

So i change this to:

GetSQLValueString($_POST(['newsbody'], "text") = str_replace("\r", "<br />", str_replace("\n", "", ['newsbody'], "text"))),
0
 
LVL 35

Accepted Solution

by:
Raynard7 earned 250 total points
ID: 17877692
I would change the line

GetSQLValueString($_POST['newsbody'], "text")

to

str_replace("\r", "<br />", str_replace("\n", "", GetSQLValueString($_POST['newsbody'], "text")))
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now