Solved

PHP Formating in Dreamweaver

Posted on 2006-11-05
6
341 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

724 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