我想合并两个sql数据库的功能?

model page

function msghead1($a)
        {
            $r=mysql_query("SELECT * FROM messagedetails JOIN admission_msg ON messagedetails.s_no=admission_msg.msg_id and adm_no='$a'   ORDER BY s_no desc;");
            return $r;
        }
    function msghead2($a)
        {
            $r=mysql_query("SELECT * FROM messagedetails where status='$a' or status='Al' ORDER BY s_no desc;");
            return $r;
        }

main page

        $bid=0;
        $bid=0;
        include 'model.php';
        $db=new database;
        $r=$db->msghead1($admno,$sclass);
        while($row= mysql_fetch_array($r))
        {
            $id=$row[0];
            $title=$row[1];
            $msg=$row[2];
            $date=$row[3];
            $sender=$row[4];
            $tit_status=$row["title_status"];
            $bid=$bid+1;
            $pid=$pid+1;

        include'msg.php';
        } 

        $r1=$db->msghead2($sclass);

        while($row= mysql_fetch_array($r1))
        {
            $id=$row[0];
            $title=$row[1];
            $msg=$row[2];
            $date=$row[3];
            $sender=$row[4];
            $tit_status=$row["title_status"];
            $bid=$bid+1;
            $pid=$pid+1;

            include'msg.php';
        }           
        ?>

this are two functions of my model working on same table but problem is that i have to use output of both function to print in single order... although they are in order but when order of first finishes than the order of second starts. means they are using order differently .. any doubt in question you can ask

try this

    $bid=0;

    include 'model.php';
    $db=new database;
    $r=$db->msghead1($admno,$sclass);
    while($row= mysql_fetch_array($r))
    {
        $id=$row[0];
        $title=$row[1];
        $msg=$row[2];
        $date=$row[3];
        $sender=$row[4];
        $tit_status=$row["title_status"];
        $bid=$bid+1;
        $pid=$pid+1;

    include'msg.php';
    } 

    $r1=$db->msghead2($sclass); 

    $bid=0; // here i change

    while($row= mysql_fetch_array($r1))
    {
        $id=$row[0];
        $title=$row[1];
        $msg=$row[2];
        $date=$row[3];
        $sender=$row[4];
        $tit_status=$row["title_status"];
        $bid=$bid+1;
        $pid=$pid+1;

        include'msg.php';
    }           
    ?>
    <div class="item">
<button style="width:90%;height:40px; margin-left:5%;"  onclick="MessageDetailsById(<?php echo $id;?>)">
<?php     if($tit_status=="1")      {   ?>      
        <i class="fa fa-plus-circle" aria-hidden="true" style="width:20px;float:left;"></i>  <i class="fa fa-envelope-open-o" aria-hidden="true"></i>&nbsp;<span id="active" class="sidebar-title" ><?php echo $title; ?></span> &nbsp;&nbsp;<?php echo $date;?>
  <?php    }
 else
{    ?>     
<i class="fa fa-plus-circle" aria-hidden="true" style="width:20px;float:left;"></i> <i class="fa fa-envelope-o" aria-hidden="true"></i>&nbsp;<span  id="active<?php echo $tit_status;?>" class="sidebar-title" style="color:red;"><?php echo $title;  ?></span> &nbsp;&nbsp;<?php echo $date;?>
<?php   }                   ?>
   </a></button>
<p style="display:none;margin-left:5%;" id="<?php echo $id; ?>">       <?php echo $msg; ?>  </p>
  </div>

this is msg.php code but it is working fine