dongzhao4036 2013-12-26 11:00
浏览 17

mysql_fetch_array()期望参数1是资源,布尔给定[重复]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php 
 $con = mysql_connect("localhost","root","");
    if(!$con)
    {
    die("cannot connect" . mysql_error());
    }
    mysql_select_db("library",$con);

    $sql = "SELECT Renewal_Date FROM ilist where Student_Id=?";
    $mydata = mysqli_query($sql,$con);
    $result_array = array();
     echo "<table border=2 >
    <tr>

       <th>Renewal_Date</th>
    </tr>";


  while($record = mysql_fetch_array($mydata)){

  echo"<tr>";
  echo "<td>" . $record['Renewal_Date'] . "</td>";
  echo "</tr>";
  $todayDate = date('m/d/Y');
  $date1 = new DateTime($todayDate);
  $date2 = new DateTime($record['Renewal_Date']);
  if($date2 < $date1)
    {
  $interval = $date1->diff($date2); 
  echo "difference " . $interval->y . " years, " . $interval->m." months, ".$interval->d."        days ";
  echo"<p>";
  $extradays=$interval->m;
if($extradays==1)
{
    $eday=1;
    }else if($extradays==3){
        $eday=2;
        }   else if($extradays==5){
            $eday=3;
                }   else if($extradays==7){
                    $eday=4;
                    }   else if($extradays==8){
                        $eday=5;
                        }   else if($extradays==10){
                            $eday=6;
                            }   else if($extradays==12){
                                $eday=7;
                                }
                                else{
            $eday=0;
        }

$yd= $interval->y*365*3+$interval->d*3;

    $ydm=$yd+$interval->m*30*3;
    $ydm=$ydm+($eday*3);
    echo $ydm;
}
else
{
    echo $ydm=0;
    }
}
?>
<body>
</body>
</html>

the same code was working in my desktop but in laptop it is showing mysql_fetch_array() expects parameter 1 to be resource, boolean given... error in while loop. what would be the reason? i just want to fetch renewal date from database and do some calculations. logic is completely fine since it was working perfectly in my desktop, but in laptop this error is occuring, please help. `

</div>
  • 写回答

3条回答 默认 最新

  • duanguane1670 2013-12-26 11:02
    关注

    First :
    Stop using mysql_query as it has been deprecated.

    Second: Even though you are using it. PLease do not mix it with mysqli

    Third: If you have used a placeholder in your query then please do not forget to bind the value as well

    $sql = "SELECT Renewal_Date FROM ilist where Student_Id=?";
    

    YOU forgot to bind the value for ?

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向