I want to print only year of date store in table example if 2001-12-29 stored in db table so print only number.

<?php
include_once("connect.php");
if($search=mysql_query("SELECT year( Date_Of_Admission )  FROM student_enroll where Seat_Number='$_POST[seat]'"))
{

//echo "<br/>";
echo "<table border='1'>
<tr>
<th>Seat Number</th>
<th>Batch</th>
</tr>";
while($row=mysql_fetch_array($search))
{
echo "<tr>";
echo "<tr>";
echo "<td>".$row['Seat_Number']."</td>";
echo "<td>".year."</td>";
echo "</tr>";
}
echo "</table>";
}

?>

how i print only year??

mysql_query("SELECT YEAR(Date_Of_Admission) AS Admission_Year FROM student_enroll WHERE Seat_Number='$_POST[seat]'")
// ...
echo "<td>".$row['Admission_Year']."</td>";

also with yout post if you taking it from the user / webuser you should
validate it for code and what not before it goes into your sql and you only have to
change your one line to get the year

</td>";
echo "<td>".year."</td>";

to

echo "<td>".$row['year']."</td>";

you can also echo over diffrent lines no need for echo on each line

<?php
    include_once("connect.php");
    if($search=mysql_query("SELECT year( Date_Of_Admission ) FROM student_enroll where Seat_Number='$_POST[seat]'"))
    {
     
    //echo "<br/>";
    echo "<table border='1'>
    <tr>
    <th>Seat Number</th>
    <th>Batch</th>
    </tr>";
    while($row=mysql_fetch_array($search))
    {
    echo "<tr>
<tr>
<td>".$row['year']."</td></tr>";
    }
    echo "</table>";
    }
     
    ?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.