Reputation: 1659
I've been giving myself a basic refresher course in PHP without using template engines (although I've learnt some Smarty and Twig recently I felt I should keep practising basic PHP), and this is my basic page displaying a list of vehicles and when they were registered:
<?php
// Connects to your Database
mysql_connect("localhost", "testing", "testingpass") or die(mysql_error());
mysql_select_db("cars1") or die(mysql_error());
$data = mysql_query("SELECT * FROM autos")
or die(mysql_error());
echo "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
"<tr>";
//echo "<td>"date("d M Y",strtotime($info['registered']));"</td> ";
echo "<td><tr>".$info['make'] ." ".$info['model'] ."</td><tr> ";
}
echo "</table>";
?>
It works if the datetime is commented out, but if it's uncommented the page appears blank - I'm using MAMP as my webserver, latest PHP.
For a simple page this works well, but how should I format this date? (I used the tutorial at http://erikastokes.com/mysql-help/display-mysql-dates-in-other-formats.php to try this).
What changes should I make to fix this problem with the date and time, as otherwise it works well as a basic MySQL php query.
Upvotes: 0
Views: 724
Reputation: 8223
First off, the reason your screen is blank, is because most default PHP installs have error reporting turned off. You'll need to edit your php.ini file to fix that. Open and search for display_errors
and change it.
Second, the first error you're missing is you just have "<tr>"
with no echo
before it.
The second error you're most likely not seeing is that you're missing a concatenating operator .
echo "<td>"date("d M Y",strtotime($info['registered']));"</td> "
should be
echo "<td>" . date("d M Y",strtotime($info['registered'])) . "</td> "
Upvotes: 0
Reputation: 6192
it should be like this
echo "<td>".date("d M Y",strtotime($info['registered']))."</td> ";
You have to use .
for concantinate string.
Upvotes: 2