php 报错如下:Notice: Trying to get property of non-object
参考文档如下解决:
https://stackoverflow.com/questions/5891911/trying-to-get-property-of-non-object-in
问题如下:
This question already has an answer here:
on Control page:
<?php
include 'pages/db.php';
$results = mysql_query("SELECT * FROM sidemenu WHERE `menu_id`='".$menu."' ORDER BY `id` ASC LIMIT 1", $con);
$sidemenus = mysql_fetch_object($results);
?>
on View Page:
<?php foreach ($sidemenus as $sidemenu): ?>
<?php echo $sidemenu->mname."<br />";?>
<?php endforeach; ?>
Error is:
Notice: Trying to get property of non-object in C:\wamp\www\phone\pages\init.php on line 22
Can you fix it? I don't have any idea what happened.
解决如下:
Check the manual for mysql_fetch_object(). It returns an object, not an array of objects.
I'm guessing you want something like this
$results = mysql_query("SELECT * FROM sidemenu WHERE `menu_id`='".$menu."' ORDER BY `id` ASC LIMIT 1", $con);
$sidemenus = array();
while ($sidemenu = mysql_fetch_object($results)) {
$sidemenus[] = $sidemenu;
}
Might I suggest you have a look at PDO. PDOStatement::fetchAll(PDO::FETCH_OBJ) does what you assumed mysql_fetch_object() to do
php 报错如下:Notice: Trying to get property of non-object的更多相关文章
- [one day one question] webpack 打包报错 Cannot assign to read only property 'exports' of object '#<Object>'
问题描述: webpack 打包报错 Cannot assign to read only property 'exports' of object '#<Object>',这怎么破? 解 ...
- DataTable插件报错:Uncaught TypeError: Cannot read property 'style' of undefined
DataTable插件报错:Uncaught TypeError: Cannot read property 'style' of undefined 原因:table 中定义的列和aoColumns ...
- vue 项目报错,提示:Cannot read property '$createElement' of undefined at render ...
vue 项目报错,提示:Cannot read property '$createElement' of undefined at render ...
- JS报错:Uncaught TypeError: Cannot set property ‘nTf‘ of undefined
在使用DataTable时,遇到以下报错: Uncaught TypeError: Cannot set property 'nTf' of undefined ... ... 初步排查后发现是< ...
- 【Linux】 解决报错: ImportError: libSM.so.6: cannot open shared object file: No such file or directory
centos7 + python3.6.4 我使用 pip3 install opencv-python 安装了opencv-python 之后,在使用 import cv2 报错如下 报错原因 ...
- gcc报错 can not be used when making a shared object; recompile with -fPIC
使用google protobuf时,出现错误 /usr/bin/ld: /usr/local/lib/libprotobuf.a(message_lite.o): relocation R_X86_ ...
- PyCharm+selenium环境搭建报错:Traceback (most recent call last): TypeError: 'module' object is not callable
环境搭建好后,代码如下: from selenium import webdriverdriver = webdriver.chrome()driver.get("http://www.ba ...
- 【spring mvc】后台API查询接口,get请求,后台Date字段接收前台String类型的时间,报错default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'createDate';
后台API查询接口,get请求,后台Date字段接收前台String类型的时间筛选条件 后台接口接收 使用的实体 而createDate字段在后台实体中是Date类型 报错信息: org.spring ...
- springboot整合mybatis的时候报错Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
今天闲来无事,学习springboot整合mybatis,在bilibili看视频学的,视频中在dao层的interface上面加上org.apache.ibatis.annotations.Mapp ...
- vue 报错解决:TypeError: Cannot read property '_t' of undefined"
前端报错如下: [Vue warn]: Error in render: "TypeError: Cannot read property '_t' of undefined" 是 ...
随机推荐
- set(集合)数据类型【七】
一.概述:(类似于Java的Set,不允许有重复元素) 在Redis中,我们可以将Set类型看作为没有排序的字符集合,和List类型一样,我们也可以在该类型的数据值上执行添加.删除或判断某一元素是否存 ...
- rsync远程文件传输
[root@rhel5 ~]# rsync -a log.tar.gz root@192.168.124.129:/tmp root@192.168.124.129's password: Permi ...
- java 判断一个字符串是否为纯数字
if (getUid().matches("[0-9]+")) { Log.v("纯数字");} else { Log.v("非纯数字"); ...
- BitMap算法 .net实现 用于去重并且排序,适用于大型权限管理 ,大数据去重排序
BitMap利用byte特性 针对排序+去重 最佳实践: 100万条数据的排序+去重用时200毫秒左右 static void Main(string[] args) { ]; /*alias*/ ...
- Word Search(深度搜索DFS,参考)
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...
- codevs 3498 小木棍
3498 小木棍 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 乔治有一些同样长的小木棍,他把这些木棍随意 ...
- Linux系统备份还原工具1(DD)(应用实例)
DD使用教程:http://www.cnblogs.com/EasonJim/p/7442223.html 以下实例没经过大量测试,可能在一些机器上不会有效. 一般围绕以下几点进行设置: 1.dd完后 ...
- TensorFlow-GPU环境配置之一——安装Ubuntu双系统
本机已经安装过Windows系统,准备安装Ubuntu双系统进行TensorFlow相关工作,需要在windows中将磁盘分出一定空间供Ubuntu使用 1.首先下载Ubuntu17.04版本ISO ...
- how to read openstack code : paste deploy
本篇分为以下几个部分 paste 是什么 怎样使用paste paste of neutron paste 是什么 WSGI 是python 中application 和 web server互通的标 ...
- 介绍css 的3D 变换(3D transform)
https://desandro.github.io/3dtransforms/docs/card-flip.html ---------------------------------------- ...