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
Solved

PHP Formating in Dreamweaver

Posted on 2006-11-05
6
338 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

809 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