连接具有特定行的多个表

时间:2014-08-29 05:47:28

标签: php mysqli

我有一个问题。我想从表 stafhan 中显示 nama ,其中 nric 与表 tempahan中的 nric 相同 EM>。我试着像下面的代码,但我只是错误

  

警告:mysqli_fetch_array()要求参数1为mysqli_result,在第120行的C:\ xampp \ htdocs \ New folder \ permohonan_stk.php中给出布尔值

任何人都可以帮助我吗?

    <?php
        include 'include\opendb.php';
        $i = "SELECT tempahan.tarikh_mohon, tempahan.tarikh, tempahan.masa_dari, tempahan.masa_hingga, tempahan.dari_daerah, tempahan.hingga_daerah, tempahan.tujuan, tempahan.status, staf.nama, staf.nric 
        from tempahan, staf
        WHERE staf.nric = tempah.nric";
        $h = mysqli_query($mysqli, $i);         
        $row=mysqli_fetch_array($h);



        while( $row1 ){

    ?>

    <tr>

        <td><center><?php echo $row['tarikh_mohon']; ?></center></td>
        <td><center><?php echo $row['nama']; ?></center></td>
        <td><center><?php echo $row['tarikh']; ?></center></td>
        <td><center><?php echo $row['masa_dari']; ?></center></td>
        <td><center><?php echo $row['masa_hingga']; ?></center></td>
        <td><center><?php echo $row['dari_daerah']; ?></center></td>
        <td><center><?php echo $row['dari_daerah']; ?></center></td>
        <td><center><?php echo $row['tujuan']; ?></center></td>
        <td><center><?php echo $row['status']; ?></center></td>
    </tr>
    <?php
        }

    ?>

1 个答案:

答案 0 :(得分:0)

请看这个:

$con=mysqli_connect("localhost","user","password","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql="SELECT tempahan.tarikh_mohon, tempahan.tarikh, tempahan.masa_dari,
 tempahan.masa_hingga, tempahan.dari_daerah, tempahan.hingga_daerah, tempahan.tujuan, tempahan.status, staf.nama, staf.nric 
from tempahan, staf WHERE staf.nric = tempah.nric";

$result=mysqli_query($con,$sql)

// Numeric array
$row=mysqli_fetch_array($result,MYSQLI_NUM);

 while( $row1 ){

    ?>
.....................
...............

有关mysql_fetch_array的更多参考:http://php.net/manual/en/function.mysql-fetch-array.php

相关问题