Final question from me for the week (promise) and it's a real Noobie special
I want to format my date to appear as dd-mm-yyyy when it appears on the page. I've been through lots of previous posts on the subject and I understand that it's best to use mySQL's date_format to do this - but I can't for the life of me figure out how to include that into the existing query without breaking it (again and again and again...).
I think this is the relevant bit that needs the date_format adding to it:
Code: Select all
$result = @mysql_query('select id, newsdate, newssummary from archive ORDER BY newsdate DESC');I'd be pathetically grateful if anyone can explain how to fit date_format into the above bit of code (once you've all stopped laughing of course!)
For the record, and in case I've got the wrong bit above - the complete code looks like this:
Code: Select all
<?php
$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("mydatabase");
echo '<h3>Here are all our news items: </h3>';
$result = @mysql_query('select id, newsdate, newssummary from archive ORDER BY newsdate DESC');
if (!$result) {
exit('<p>Error performing query: ' .
mysql_error() . '</p>');
}
while ($row = mysql_fetch_array($result)) {
$newsid = $row['id'];
$newsdate = $row['newsdate'];
$newssummary = $row['newssummary'];
echo "<p>" . $newsdate . "<br />" .
"<a href='news2.html?id=$newsid'>" . "<img src=\"images/doc.gif\" alt=\"news item\">" . $newssummary . "</a>" . "</p>";
}
$newssummary = htmlspecialchars($newssummary);
$newstext = htmlspecialchars($newstext);
?>Noobie