dounuo8797 2015-05-20 04:25
浏览 69

是否可以将许多MYSQL语句组合成一个查询?

I'm a beginner in PHP and MySQL and I'm still in learning process. Is it possible to combine many MySQL statement into one query? This is because I want to display every new output into new row in a table. The coding below is not the right way to display the output like what I want.

<table>
<tr>
        <th>Staff Name</th>
        <th>Staff No.</th>
        <th>Grade</th>
        <th>Position</th>
        <th>Department</th>
</tr>
<tr>
    <?php
    $query="select staffName, staffNo from tblstaff";       
    $result=mysql_query($query) or die (mysql_error());     
    while($row= mysql_fetch_array($result))
    {
    ?>
        <td><?php echo $row['staffName']; ?></td>
        <td><?php echo $row['staffNo']; ?></td> 
    <?php
    }
    ?>   
    <?php
    $query="select grade, gradePosition, gradeDepartment from tblgrade";        
    $result=mysql_query($query) or die (mysql_error()); 
    while($row= mysql_fetch_array($result))
    {
    ?>
        <td><?php echo $row['grade']; ?></td> 
        <td><?php echo $row['gradePosition']; ?></td> 
        <td><?php echo $row['gradeDepartment']; ?></td> 
    <?php
    }
    ?>   
</tr>
</table>

The result for the above code is all the staff name and staff no in database table out first and then follow by all grade, position and department in a database table displayed in a row of the table. The output is not sequence accordingly like I want. Can anyone help me to solve my problem?

Thank you in advance.

</div>
  • 写回答

2条回答 默认 最新

  • 普通网友 2015-05-20 04:44
    关注

    Yes it is possible. Use mysqli_multi_query() function.

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题