PHP - 帮助警告:缺少参数

file LoaiSP.php :

enter code here<?php
                       $idLoai=$_GET['idLoai'];
                       $SPTrongLoai=SPTrongLoai(1,$idLoai);
                       while($row_loaisp=mysql_fetch_array($SPTrongLoai)){
                       ?>
                         <div class="loaisp" align="center"><?php echo $row_loaisp['TenSP']?><br />
                          <a href="" data-tooltip="sticky1"><img src="<?php echo $loai_sp['UrlHinh']?>" width="70" height="70" border="0" /></a><br />
                              <img src="img/new.gif" width="29" height="19" /><br />
                            Gía : <span class="text"><?php
                            echo number_format($row_loaisp['Gia'],2);?></span> VNĐ<br />
                            <a href="index.php?page=chitiet&idSP=<?php 
                            echo $row_loaisp['idSP']?>"><img src="img/chitiet.png" width="70" height="25" border="0" /></a><img onclick="chonSP('chonsp.php?idSP=<?php echo $_row_loaisp['idSP']?>')" src="img/mua.png" width="70" height="25" /></div>
                            <?php }?>

file function.php :

function SPTrongLoai($AnHien,$idLoai,$from,$sosp1trang){
  $sql="select idSP,TenSP,UrlHinh,Gia,MoTa from sanpham where AnHien=$AnHien and idLoai=$idLoai limit $from,$sosp1trang";
  $kq=mysql_query($sql);
  return $kq;
}

Error message :

**Warning: Missing argument 3 for SPTrongLoai(), called in C:\AppServ\www\banhoatuoi\LoaiSP.php on line 13 and defined in C:\AppServ\www\banhoatuoi\function.php on line 32

Warning: Missing argument 4 for SPTrongLoai(), called in C:\AppServ\www\banhoatuoi\LoaiSP.php on line 13 and defined in C:\AppServ\www\banhoatuoi\function.php on line 32

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\banhoatuoi\LoaiSP.php on line 14**

$SPTrongLoai=SPTrongLoai(1,$idLoai);

Warning: Missing argument 3 for SPTrongLoai(), called in C:\AppServ\www\banhoatuoi\LoaiSP.php on line 13 and defined in C:\AppServ\www\banhoatuoi\function.php on line 32

It said that: SPTrongLoai() has 4 parameters. But You only provide 2 parameters (1 and $idLoai). You was miss 2 parameter $from and $sosp1trang

Please check your function (SPTrongLoai()).

UPDATE: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\banhoatuoi\LoaiSP.php on line 14**

  1. It said that: The result is invalid.

  2. Try to use below code before use mysql_fetch_array

    if ($SPTrongLoai && mysql_num_rows($SPTrongLoai) != 0) {

    // Your loop is here;
    

    }

The function definition asks for 4 arguments to the function SPTrongLoai(). You need to call the function with 4 arguments or use default values for the function parameters like this :

<?php
  function makecoffee($type = "cappuccino")
  {
    return "Making a cup of $type.
";
  }
 echo makecoffee();
 echo makecoffee(null);
 echo makecoffee("espresso");
?>

So either call like this. The last two arguments are used to set limit:

$SPTrongLoai=SPTrongLoai(1,$idLoai,0,30);