Forum Moderators: coopster
CREATE TABLE `sometablename` (
`ID` bigint(20) UNSIGNED NOT NULL,
`christian_name` varchar(60) NOT NULL DEFAULT '',
`middle_name` varchar(64) NOT NULL DEFAULT '',
`surname` varchar(50) NOT NULL DEFAULT '',
`date_of_birth` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`preferred_name` varchar(64) NOT NULL,
`maiden_name` varchar(64) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
SELECT * FROM `sometablename` ORDER BY MONTH(date_of_birth),DAY(date_of_birth) and the order is okay. However, wanted to use php and provide a nice looking list, as per example above. My php is quite rusty; haven't used it for quite a while.
<?php
$con=mysqli_connect($hostname,$username,$pwd, $dbname);
#
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM $table_name ORDER BY MONTH(date_of_birth),DAY(date_of_birth)");
echo "<table border='1'>
<tr>
<th>Year</th>
<th>Firstname</th>
<th>Lastname</th>
<th>DateofBirth</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row[YEAR('date_of_birth')] . "</td>";
echo "<td>" . $row['christian_name'] . "</td>";
echo "<td>" . $row['surname'] . "</td>";
echo "<td>" . $row['date_of_birth'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
PHP Fatal error: Call to undefined function YEAR()
PHP Warning: mysqli_connect() expects parameter 1 to be string, array given in /************.php on line 9
<?php echo date('Y'); ?> <?php
$con=mysqli_connect($hostname,$username,$pwd, $dbname);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM $table_name ORDER BY MONTH(date_of_birth),DAY(date_of_birth)");
echo "<table border='1'>
<tr>
<th>Year</th>
<th>Name</th>
<th>Date</th>
<th>Parent</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
$datetime = new DateTime($row['date_of_birth']);
if (empty($row['preferred_name'])) {
$name = $row['christian_name'];
} else {
$name = $row['preferred_name'];
}
echo "<tr>";
echo "<td>" . $datetime->format('Y') . "</td>";
echo "<td>" . $name . "</td>";
echo "<td>" . $datetime->format('M') . " " . $datetime->format('d') . "</td>";
echo "<td>" . $row['Parent'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?> $con=mysqli_connect($hostname,$username,$pwd, $dbname); Is it possible to replace this line .. $con=mysqli_connect($hostname,$username,$pwd, $dbname);