Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我想合并到sql数据库的函数?_Php_Mysql - Fatal编程技术网

Php 我想合并到sql数据库的函数?

Php 我想合并到sql数据库的函数?,php,mysql,Php,Mysql,模型页 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 msghead

模型页

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;
        }
主页

这是我的模型在同一张表上运行的两个函数,但问题是我必须使用这两个函数的输出以单顺序打印。。。虽然它们是有序的,但当第一个顺序结束时,第二个顺序开始。意味着他们使用的顺序不同。。如果有任何疑问,你可以问

试试这个

    $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';
    }           
    ?>


您的PHP脚本应该做什么?它从数据库中获取数据并根据日期打印,但我获取了两种类型的数据,所以我希望以单一顺序合并这些数据
    $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>