I have the following query to find out who is the oldest in the family from the tbl_student table.
Code: Select all
<?php
select tbl_student.stuid as older_stuid,stu_fname1,stu_lname from tbl_student where frn_familyid = $frn_familyid and ((tbl_student.stu_status = 1) or (tbl_student.stu_status = 3 and tbl_student.stu_tid != 0)) order by tbl_student.stu_dob asc
?>THE QUERY ABOVE IS SLOWING EVERYTHING DOWN. ANY OTHER WAY I CAN GET THE OLDEST SIBLING FROM THE TABLE?
This is the whole process
Code: Select all
<?php
$sql_studentP = "select stu_no,frn_familyid,stu_leaving,stu_dob,frn_stgid,stu_sex,frn_eqid,stu_status,stu_tid,stu_dob,stu_payment,stuid,stu_fname1,stu_fname2,stu_lname,frn_eqid from tbl_student where frn_scid = $chosen_schoolid and stu_status = $stat order by $ordfi $ordti";
$mysql_result_studentP = mysql_query($sql_studentP,$my_conn);
while ($row = mysql_fetch_array($mysql_result_studentP))
{
$stuid = $row["stuid"];
$stu_fname1 = $row["stu_fname1"];
$stu_fname2 = $row["stu_fname2"];
$stu_lname = $row["stu_lname"];
$stu_payment = $row["stu_payment"];
$dob_temp = $row["stu_dob"];
$frn_eqid = $row["frn_eqid"];
$stu_status = $row["stu_status"];
$stu_tid = $row["stu_tid"];
$frn_eqid = $row["frn_eqid"];
$stu_dob = $row["stu_dob"];
$stu_sex = $row["stu_sex"];
$frn_stgid = $row["frn_stgid"];
$frn_familyid = $row["frn_familyid"];
$stu_leaving = $row["stu_leaving"];
$stu_no = $row["stu_no"];
$sql_siblingP = "select tbl_student.stuid as older_stuid,stu_fname1,stu_lname from tbl_student where frn_familyid = $frn_familyid and ((tbl_student.stu_status = 1) or (tbl_student.stu_status = 3 and tbl_student.stu_tid != 0)) order by tbl_student.stu_dob asc";
$mysql_result_siblingP = mysql_query($sql_siblingP,$my_conn);
$num_rows_siblingP = mysql_num_rows($mysql_result_siblingP);
$get_siblingP = mysql_fetch_assoc($mysql_result_siblingP);
$oldest_name = $get_siblingP['stu_fname1'] . " " . $get_siblingP['stu_lname'];
}
?>