sorry, need more help with time

This is a discussion on "sorry, need more help with time" within the PHP Forum section. This forum, and the thread "sorry, need more help with time are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 6th, 2007, 16:20
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,281
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
sorry, need more help with time

i was kindly helped with a problem with my date this morning, but i have been trying to figure out this

this is the date format i want,
Quote:
06th October 2007
but all i am able to get is
Quote:
1191661576
after the blog is posted

its fine at form
its fine at database
i just need to change the format once it is called from the database and printed on the page

form.php
PHP: Select all

<?php error_reporting(E_ALL );?>
<?php 
include 'config.php';?>
<?php
$conn 
mysql_connect($dbhost$dbuser$dbpass) or die ('Error connecting to mysql');
function 
filterThis($string) {
$string htmlentities($string);
$string mysql_real_escape_string($string);
return 
$string; }
$title '$string';
$date '$string' ;
$subject '$string';
$blog_mes '$string';
$string filterThis($title);
$string filterThis($date);
$string filterThis($subject);
$string filterThis($blog_mes);
$query sprintf("SELECT * FROM form WHERE title='%s' AND date='%s' AND subject='%s' AND blog_mes='%s'",
mysql_real_escape_string($title),
mysql_real_escape_string($date),
mysql_real_escape_string($subject),
mysql_real_escape_string($blog_mes));
 
if (isset(
$_POST['submit'])) {
  
$title $_POST['title'];
  
$date $_POST['date'];
  
$subject $_POST['subject'];
  
$blog_mes $_POST['blog_mes'];
  
$sql="INSERT INTO form (title, date, subject, blog_mes)
        VALUES ('$title', " 
time() .", '$subject', '$blog_mes')";  
mysql_select_db("$dbname",$conn);
mysql_query($sql) or die (mysql_error());
}
?>
blogform.php
PHP: Select all

<script language="javascript" type="text/javascript" src="../jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
 mode : "textareas"
});
</script>
<?php include 'config.php';?>
<?php $d 
=  date("dS F Y")?>
<?php 
include("form.php"); ?> 
<div align="center">
  <form action="<?php echo $_SERVER['PHP_SELF'?>" method="post">
    <p><input name="title" type="text" value="TITLE" size="100">
    </p>
    <table width="600" height="39" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="270"><input name="date" type="text" value="<?php echo($d); ?> "45"></td>
        <td width="58">&nbsp;</td>
        <td width="136">
          <label></label>
          <div align="center"><strong>SUBJECT:</strong></div></td>
        <td width="136"><select name="subject" size="1" id="subject">
<option>choose...</option>
<option>website design tips</option>
                        </select></td>
      </tr>
    </table>
    <p>
      <?php include ("created.php");?>
    </p>
    <label></label>
    <p>
      <textarea name="blog_mes" cols="100" rows="15">BLOG MESSAGE</textarea>
    </p>
    <table width="632" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="494">&nbsp;</td>
        <td width="138"><div align="right">
          <input type="submit" name="submit" value="SUBMIT BLOG">
        </div></td>
      </tr>
    </table>
  </form>
</div>
</body>
</html>
main.php
PHP: Select all

<?php include 'config.php'
$conn mysql_connect($dbhost$dbuser$dbpass) or die ('Error connecting to mysql'); 
mysql_select_db$dbname$conn ); 
$perPage 5// number to display on per page 
// Start by counting the number of posts 
$res mysql_query ("SELECT count(*) AS num FROM form") or die (mysql_error() . 'dying hurts'); 
$num mysql_fetch_assoc($res); 
$num $num['num']; 
mysql_free_result($res); 
// now work out how many pages there are, check if page has been sent via GET 
$numPages ceil($num $perPage); 
// Check to make sure pagenum will be 1 or greater, less than numpages and an actual number 
$pageNum  = (!empty($_GET['id']) &&  
             
is_numeric($_GET['id']) &&  
             
$_GET['id'] > 1)  
 
             ? (
$_GET['id'] < $numPages ?  ($_GET['id']) : $numPages) : 1// Set to 1 if not set or something dodgy 
// Okay, now we run the query and set the limits LIMIT xx, yy (x= start from , y= limit) 
$sql "SELECT * FROM form ORDER BY date DESC LIMIT " . ($pageNum 1) * $perPage ", $perPage"
$res mysql_query($sql$conn) or die(mysql_error()); 
while (
$row mysql_fetch_object($res)) {          
print  
$row->title ;   
echo 
nl2br("\n");   
print 
$row->date ;   
print 
$row->blog_mes;   

// Some paginananananananation 
echo '<div>'
for (
$i 1$i <= $numPages$i++) 

    if (
$pageNum != $i
    echo 
'<a href="page_1.php?id='$i'">'$i'</a> '
    else  
    echo 
'<b>'$i'</b>'

echo 
'</div>'
?>
thank you
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Oct 6th, 2007 at 16:24.
Reply With Quote

  #2 (permalink)  
Old Oct 6th, 2007, 20:07
Junior Member
Join Date: Oct 2007
Location: Durham UK
Age: 23
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Re: sorry, need more help with time

Have you selected the date format for example:

SELECT *, DATE_FORMAT(date,'%D %M %Y') as fdate FROM form

Using the formated date

http://www.plus2net.com/php_tutorial...ate_format.php
Reply With Quote
  #3 (permalink)  
Old Oct 6th, 2007, 20:09
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,281
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: sorry, need more help with time

which one would i need to put it into and where, i have tryed doing it but failed
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Reply With Quote
  #4 (permalink)  
Old Oct 6th, 2007, 20:14
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdRock
Re: sorry, need more help with time

This is what I use

PHP: Select all

DATE_FORMAT(eventdate'%W %D %M %Y') as date 

If you want to format the date on output, when you do the SELECT, use the fieldnames then use the DATE_FORMAT i mentioned

Last edited by AdRock; Oct 6th, 2007 at 20:17.
Reply With Quote
  #5 (permalink)  
Old Oct 6th, 2007, 20:20
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,281
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: sorry, need more help with time

i must be putting it in the wrong place or pages, i just cant figure out where this needs to be
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Reply With Quote
  #6 (permalink)  
Old Oct 6th, 2007, 20:26
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdRock
Re: sorry, need more help with time

Quote:
Originally Posted by saltedm8 View Post
i must be putting it in the wrong place or pages, i just cant figure out where this needs to be
When you want to output whatever it is being output, you obviously have to connect to the database to get the record.

When you perform the query to select the record and use use SELECT * FROM wherever, you need to select all the fileds in the database that are being selected instead of using * and the field that has the date, you then use DATE_FORMAT(eventdate, '%W %D %M %Y') as date
Reply With Quote
  #7 (permalink)  
Old Oct 6th, 2007, 20:28
Junior Member
Join Date: Oct 2007
Location: Durham UK
Age: 23
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Re: sorry, need more help with time

Quote:
Originally Posted by AdRock View Post
When you want to output whatever it is being output, you obviously have to connect to the database to get the record.

When you perform the query to select the record and use use SELECT * FROM wherever, you need to select all the fileds in the database that are being selected instead of using * and the field that has the date, you then use DATE_FORMAT(eventdate, '%W %D %M %Y') as date
What He Said

Take it away AdRock I'll leave it in your hands
Reply With Quote
  #8 (permalink)  
Old Oct 6th, 2007, 20:32
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,281
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: sorry, need more help with time

Quote:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DATE_FORMAT(eventdate, '%W %D %M %Y') as date , subject, blog_me
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Oct 6th, 2007 at 20:35.
Reply With Quote
  #9 (permalink)  
Old Oct 6th, 2007, 20:38
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdRock
Re: sorry, need more help with time

In my example have you changed the eventdate to the correct date field in your database?
Reply With Quote
  #10 (permalink)  
Old Oct 6th, 2007, 20:45
Junior Member
Join Date: Oct 2007
Location: Durham UK
Age: 23
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Re: sorry, need more help with time

On Line 19 in main.php

replace $sql = "SELECT * FROM form

With
$sql = "SELECT *, DATE_FORMAT(date,'%D %M %Y') as fdate FROM form

And line 24 with

print $row->fdate ;




Well thats my 2cent anyway
Reply With Quote
  #11 (permalink)  
Old Oct 6th, 2007, 20:54
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdRock
Re: sorry, need more help with time

This is my query

PHP: Select all

SELECT id,title,contentDATE_FORMAT(eventdate'%W %D %M %Y') as datephoto FROM events 

where eventdate is the field in the database and date is the new (fake) field

and this is how i display the result

PHP: Select all

echo "<div id='content-right'><h3>".$title."</h3><p class='italic'>Event Date: ".$row['date']."</p><p>".nl2br($content)."</p><br /></div>\n"
Reply With Quote
  #12 (permalink)  
Old Oct 6th, 2007, 21:00
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: sorry, need more help with time

Change this line

PHP: Select all

print $row->date 
to

PHP: Select all

print strftime('%d %B %Y'$row->date); 

Because your date column is a unix timestamp you can't use mySQL date functions on it, you need to use the PHP functions.

Cheers
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #13 (permalink)  
Old Oct 6th, 2007, 21:04
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,281
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: sorry, need more help with time

thank you all for your help, but once again Rakuli cracked it, thanks mate - appresiate everyones help
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
My first time jabo Introduce Yourself 3 Feb 26th, 2008 17:33
It's about time... prizm Introduce Yourself 9 Nov 1st, 2007 12:46
Ok you get this all the time... Docherty Web Page Design 6 Nov 19th, 2005 14:55
Adjusting time from server time to local time Tim356 Classic ASP 10 Jun 21st, 2004 14:57
What's the time? Rob JavaScript Forum 2 Sep 25th, 2003 18:01


All times are GMT. The time now is 07:32.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43