i have a table in my database (Mysql),
with fields syear,
school_id ,student_id
(syear is current year),(school_id is the ID of each school,
i have more than 10 schools),(student_id is the student id) .
i want to write a php script that will assign
new ID to each students grouping it by school id using the current year.
So on every school id the new ID will be assign to student from 1,if the year changes
the school id will also start afresh again (Yearly Student Registration). and any number
that it has assign for that year will not be repeated again the same year for each school...
..i tried using mysql query but it dint work cause if i select * the ID it will assign will
be different from the id it will assign when i select a student,meanwhile i ll not want
to create any more table or field for that.
Please i will appreciate if you can help me with a script for that.Or help me correct the code below.
<?
$connection = mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db('edosis') or die(mysql_error());
$result = mysql_query("select * from student_enrollment order by student_id") or die (mysql_error());
if (mysql_num_rows($result) > 0 )
{
while($row = mysql_fetch_row($result,MYSQL_ASSOC))
{
$i++;
$school_id=$row['school_id'];
$student_id=$row['student_id'];
$eyear=date('Y');
echo "$eyear/$school_id/$student_id/$i<br/>";
}
}else{
echo 'no row found';
}
?>