1

(Working on a guestbook type page.) All entries are displayed properly with their unique names/emails/comments, however the date marked on each entry outputted has the same exact date... the date of the latest entry. I've checked the database and the entries definitely have differing dates.

Code:

$get_query = "select Name, Email, Comment, Date from entries ORDER by Id DESC;";

                $get_rs = mysql_query($get_query);


                // While there are still results
                while($get_row = mysql_fetch_array($get_rs)) {

                    $name = stripslashes($get_row["Name"]);
                    $email = stripslashes($get_row["Email"]);
                    $comment = stripslashes($get_row["Comment"]);
                    $date2 = date('D, M j, Y', strtotime($get_row['date']));
                    $tableOpen ="<table align=\"center\"><th>$name</th><tr><td>";
                    $tableClose = "</td></tr></table>";
                    $gb_str2 .= $tableOpen;
                    if(!empty($name)) {
                        // If name exists and email exists, link name to email
                        if(!empty($email)) {
                            $name="by <a href=\"mailto:$email\">$name</a>";
                        }
                        else {

                            $name="";
                        }
                    // Else make name blank 
                    } else {
                        $name = "";
                    }

                    // Append to string we'll print later on
                    $gb_str2 .= "<br/>$comment<hr><font size=1>posted on $date2 $name".$tableClose."</font><br>";


                }
                echo $gb_str2;

For instance, every single post is recorded with "posted on Mon, Jul 11, 2011" today, although there were many posts entered on other dates.

1
  • 1
    What format is your date in in the database? Just print it out as a string to make sure its in a valid format for strtotime. Commented Jul 11, 2011 at 19:24

1 Answer 1

4

It is a case-sensitive issue. In your select you have Date but in $get_row you have date. Change it to:

$date2 = date('D, M j, Y', strtotime($get_row['Date']));
Sign up to request clarification or add additional context in comments.

2 Comments

Yup fixing the case sensitive should do the trick. was about to post the same answer! nice
Can't believe I overlooked that! Thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.