Solved

PHP Formating in Dreamweaver

Posted on 2006-11-05
6
337 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

803 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