Click to See Complete Forum and Search --> : DATE_FORMAT Works on One Page, Yet Needs an Edit to Work on the Other


Joseph Witchard
12-24-2008, 12:36 AM
Hopefully someone can explain this to me, because I have yet to find anyone else who's willing to (if they know why, that is).

On my news script, I pull the date out of MySQL, use DATE_FORMAT to clean it up, and it outputs fine. However, on a test page I made that has the same news script, the only difference being that it's paginated this time, I have to use the following code to get it to output:

DATE_FORMAT(date_post, 'formatting') AS selected_date

Does anyone know why it would do this, or do I need to post the code?

chazzy
12-24-2008, 07:37 AM
You need to post mysqli approved code

Joseph Witchard
01-08-2009, 03:47 PM
Sorry this is so late. I've been having a lot of trouble lately.

Okay, here's the code using the DATE_FORMAT function. I have posted only the code that is having trouble, because the forum was saying my post was too long.

When coded this way, it displays the date just fine:
<?php

// DISPLAYING ENTRIES NOW

while ($obj = $result1->fetch_object())
{

echo "<div class='news'><a href='show_news.php/" . $obj->post_id . "/" . $obj->title . "'>" . strip_tags($obj->title, '<p><br><a><b><i>') . "</a></div>";
echo "<div class='news'><b>Posted by:</b> " . strip_tags($obj->author_name, '<p><br><a><b><i>') . " in " . strip_tags($obj->category_name, '<p><br><a><b><i>') . "</div>";
echo "<div class='news'><b>" . $obj->formatted_date . "</b></div>";
echo "<div class='news_post'>" . BBCODE(truncate(strip_tags($obj->post_body, '<p><br><a><b><i>'))) . "</div>"; }
echo "<br><br>";

// now, display the pages

for ($counter = $first_page; $counter <= $last_page; $counter++)
{

if ($counter == $page_number)
{

echo $counter;

}

else
{

echo "<a href='test_copy.php?page_number=$counter'>$counter</a>";


}

}

$result1->close(); } else { printf("Result Error %s\n", $conn->error); } $conn->close();

?>

</div>




</div>

</div>

</div>



</body>

</html>

And here, without DATE_FORMAT(), the date doesn't display at all.

<?php

// DISPLAYING ENTRIES NOW

while ($obj = $result1->fetch_object())
{

echo "<div class='news'><a href='show_news.php/" . $obj->post_id . "/" . $obj->title . "'>" . strip_tags($obj->title, '<p><br><a><b><i>') . "</a></div>";
echo "<div class='news'><b>Posted by:</b> " . strip_tags($obj->author_name, '<p><br><a><b><i>') . " in " . strip_tags($obj->category_name, '<p><br><a><b><i>') . "</div>";
echo "<div class='news'><b>" . $obj->date_posted . "</b></div>";
echo "<div class='news_post'>" . BBCODE(truncate(strip_tags($obj->post_body, '<p><br><a><b><i>'))) . "</div>"; }
echo "<br><br>";

// now, display the pages

for ($counter = $first_page; $counter <= $last_page; $counter++)
{

if ($counter == $page_number)
{

echo $counter;

}

else
{

echo "<a href='test_copy.php?page_number=$counter'>$counter</a>";


}

}

$result1->close(); } else { printf("Result Error %s\n", $conn->error); } $conn->close();

?>

</div>




</div>

</div>

</div>



</body>

</html>