Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi I've created the Message Board site as per the book but for some reason the Date & Time on both the Forum.php and read.php page aren't displaying.

 

I've tried the supplied code as well as my own and neither work so I'm assuming it might be a php setting or MySQL setting?

 

I've run the site using XAMPP on my MacOSX and also on my rented server.

 

I don't know if it makes any difference but the php.ini file timezone is set to...

 

date.timezone = "Europe/London"

 

Can you help please, many thanks

 

Grant

Share this post


Link to post
Share on other sites

I'd make a separate sample script to just test some date functions and make sure they're working all right.

Try the following in XAMPP and confirm whether date info is properly displayed or not:

 

<?php

 echo date('r') . '<br>';

 print_r(getdate());

?>

 

Please let us know what you find.

Thanks.

Share this post


Link to post
Share on other sites

HartleySan.... that worked!

 

I received

 

Fri, 20 Apr 2012 13:43:06 +0100Array

( [seconds] => 6 [minutes] => 43 [hours] => 13 [mday] => 20 [wday] => 5 [mon] => 4 [year] => 2012 [yday] => 110 [weekday] => Friday [month] => April [0] => 1334925786 )

 

So what can II try next?

 

thanks for your help!!!

Share this post


Link to post
Share on other sites

In the database the date is stored like so...

posted_on

2012-04-18 18:29:15

 

Below is the code from the page 'forum.php'

<?php # Script 15.4 - forum.php
// This page shows the threads in a forum.
include ('includes/header.html');
// Retrieve all the messages in this forum...
// If the user is logged in and has chosen a time zone,
// use that to convert the dates and times:
if (isset($_SESSION['user_tz'])) {
$first = "CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['user_tz']}')";
$last = "CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['user_tz']}')";
} else {
$first = 'p.posted_on';
$last = 'p.posted_on';
}
// The query for retrieving all the threads in this forum, along with the original user,
// when the thread was first posted, when it was last replied to, and how many replies it's had:
$q = "SELECT t.thread_id, t.subject, username, COUNT(post_id) - 1 AS responses, MAX(DATE_FORMAT($last, '%e-%b-%y %l:%i %p')) AS last, MIN(DATE_FORMAT($first, '%e-%b-%y %l:%i %p')) AS first FROM threads AS t INNER JOIN posts AS p USING (thread_id) INNER JOIN users AS u ON t.user_id = u.user_id WHERE t.lang_id = {$_SESSION['lid']} GROUP BY (p.thread_id) ORDER BY last DESC";
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) > 0) {
// Create a table:
echo '<table width="100%" border="0" cellspacing="2" cellpadding="2" align="center">
 <tr>
  <td align="left" width="50%"><em>' . $words['subject'] . '</em>:</td>
  <td align="left" width="20%"><em>' . $words['posted_by'] . '</em>:</td>
  <td align="center" width="10%"><em>' . $words['posted_on'] . '</em>:</td>
  <td align="center" width="10%"><em>' . $words['replies'] . '</em>:</td>
  <td align="center" width="10%"><em>' . $words['latest_reply'] . '</em>:</td>
 </tr>';
// Fetch each thread:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

 echo '<tr>
<td align="left"><a href="read.php?tid=' . $row['thread_id'] . '">' . $row['subject'] . '</a></td>
<td align="left">' . $row['username'] . '</td>
<td align="center">' . $row['first'] . '</td>
<td align="center">' . $row['responses'] . '</td>
<td align="center">' . $row['last'] . '</td>
  </tr>';

}

echo '</table>'; // Complete the table.

} else {
echo '<p>There are currently no messages in this forum.</p>';
}
// Include the HTML footer file:
include ('includes/footer.html');
?>

Share this post


Link to post
Share on other sites

I'm not that familiar with the message board code in the book (sorry), but am I to assume that all the posts, etc. display properly aside from the dates and times not displaying?

If that's the case, then most likely there is some mismatch between the date and time stored in the DB and what you're requesting, or there's some syntax error with the DATE_FORMAT function in the DB query.

 

Either way, I would recommend going into phpMyAdmin in XAMPP and from the "SQL" tab of the DB page, and trying to execute simple queries using the DATE_FORMAT function and static values.

See if you can't diagnose the problem like that.

 

After you do that, please let us know what you find.

I'm honestly still not 100% sure what the exact problem is, so it's hard to help.

Share this post


Link to post
Share on other sites

In order to use the function CONVERT_TZ(), the list of time zones must already be stored in MySQL, which may or may not be the case for your installation. So if the times zones are not installed the function will return a NULL value, that's why may be your are not receiving any output.

  • Upvote 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...