douzhuan1432 2010-11-24 19:42
浏览 125
已采纳

'mysql_fetch_array()提供的参数问题不是有效的MySQL结果资源'

I have a database with a table which includes among others, one column of dates (the column is titled 'date') in the format of Y-m-d.

I want to extract all the rows of data which have been logged during the current month, so I am using the following query:

$year_month = date("Y-m");
$query = "SELECT date FROM tracker WHERE date LIKE '$year_month%'";

When I execute the query and attempt to output it visually, I get the error "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line 64".

Line 64 is the beginning of the following loop:

while($row = mysql_fetch_array($result, MYSQL_ASSOC)
{
    echo "Name :{$row['date']} <br>";
}

I've scoured google and had a look here too, but I can't seem to figure out this seemingly simple problem. As far as I can tell, the actual query is executing just fine.

Any ideas?

** Additional - Call to MySQL Query Below **

$result = mysqli_query($conn, $query);

$conn refers to the following line:

$conn = @mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die ('Error connecting to MySQL');
  • 写回答

4条回答 默认 最新

  • doumei3828 2010-11-24 19:45
    关注

    Two things jump out at me:

    1. Are you sure that's the query that goes with that result? Queries like insert and delete do not have results. They return a boolean indicating success.

    2. Are you checking to make sure the query succeeded? After the line where you call mysql_query, make sure you check the result. If it's false, you can call mysql_get_error to find out what went wrong.

    EDIT: Okay, your real problem is that you're mixing mysql_* and mysqli_* commands. You need to use one or the other.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

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