我目前正在学习PHP OOP,我坚持使用结果转换,我从一个对象获取查询到数据库。 print_r结果如下所示:
Array ( [0] => Product Object ( [id] => 1 [product_title] => test product [product_description] => Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus accusamus doloribus repellat, ad eius ex et veniam reiciendis molestiae, illum dolore eaque iusto voluptatibus quia, vitae officiis ut facere quam odio aliquam modi. Quisquam unde error eos, earum ad ex non dolorem assumenda reprehenderit nam repellat, veniam voluptatem quae, architecto? [short_desc] => Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus accusamus [product_category_id] => 2 [product_price] => 10.2 [product_quantity] => 0 [product_image] => http://placehold.it/350x150 [errors] => Array ( ) [upload_errors_array] => Array ( [0] => There is no error [1] => The uploaded file exceeds the upload_max_filesize [2] => The uploaded file exceedsthe MAX_FILE_SIZE [3] => The uploaded file was only partially uploaded [4] => No file was uploaded [6] => Missing the temporary folder [7] => Failed to write file to disk [8] => A php extension stopped the file upload ) ) )
我已经用尽了所有现有的知识来从中提取[product_quantity]结果。 当我尝试使用
时echo $result['product_quantity']
我误以为是Undefined index:
如果我试图进入
$result->product_quantity;
我犯了这个错误
Trying to get property of non-object
这意味着我应该进入数组内部,然后从它获取对象属性,但是当尝试:
while ($row = mysqli_fetch_array($result)) {
$row->product_quantity;
}
我犯了这个错误:mysqli_fetch_array() expects parameter 1 to be mysqli_result
我如何到达这个对象属性,或整体 - 我做错了什么?(
很抱歉,如果这个问题很愚蠢,但我在SE上的搜索和谷歌目前还没有显示任何其他结果((