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.


 Subscribe in a reader

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

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Oct 6th, 2007, 16:20
saltedm8's Avatar
SuperMember

SuperMember
Join Date: Nov 2005
Location: here
Age: 27
Posts: 1,521
Blog Entries: 2
Thanks: 1
Thanked 11 Times in 11 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
Last Blog Entry: Strict and Transitional Doctype's (Sep 12th, 2008)

Last edited by saltedm8; Oct 6th, 2007 at 16:24.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Oct 6th, 2007, 20:09
saltedm8's Avatar
SuperMember

SuperMember
Join Date: Nov 2005
Location: here
Age: 27
Posts: 1,521
Blog Entries: 2
Thanks: 1
Thanked 11 Times in 11 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
Last Blog Entry: Strict and Transitional Doctype's (Sep 12th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Oct 6th, 2007, 20:14
Highly Reputable Member
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Oct 6th, 2007, 20:20
saltedm8's Avatar
SuperMember

SuperMember
Join Date: Nov 2005
Location: here
Age: 27
Posts: 1,521
Blog Entries: 2
Thanks: 1
Thanked 11 Times in 11 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
Last Blog Entry: Strict and Transitional Doctype's (Sep 12th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Oct 6th, 2007, 20:26
Highly Reputable Member
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Oct 6th, 2007, 20:32
saltedm8's Avatar
SuperMember

SuperMember
Join Date: Nov 2005
Location: here
Age: 27
Posts: 1,521
Blog Entries: 2
Thanks: 1
Thanked 11 Times in 11 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
Last Blog Entry: Strict and Transitional Doctype's (Sep 12th, 2008)

Last edited by saltedm8; Oct 6th, 2007 at 20:35.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Oct 6th, 2007, 20:38
Highly Reputable Member
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Re: sorry, need more help with time

In my example have you changed the eventdate to the correct date field in your database?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Oct 6th, 2007, 20:54
Highly Reputable Member
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
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"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Oct 6th, 2007, 21:04
saltedm8's Avatar
SuperMember

SuperMember
Join Date: Nov 2005
Location: here
Age: 27
Posts: 1,521
Blog Entries: 2
Thanks: 1
Thanked 11 Times in 11 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
Last Blog Entry: Strict and Transitional Doctype's (Sep 12th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may