0

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??

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by HITMANOF44th
0
mysql_query("SELECT YEAR(Date_Of_Admission) AS Admission_Year FROM student_enroll WHERE Seat_Number='$_POST[seat]'")
// ...
echo "<td>".$row['Admission_Year']."</td>";
0

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>";
    }
     
    ?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.