Solved

PHP Formating in Dreamweaver

Posted on 2006-11-05
6
336 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

895 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

14 Experts available now in Live!

Get 1:1 Help Now