可捕获的致命错误:无法将类mysqli_result的对象转换为字符串 [英] Catchable fatal error: Object of class mysqli_result could not be converted to string
问题描述
试图获取我的第一个多表MySQL数据库,但是我发现一个错误,我只能把头弄乱了.在我将计算机扔出窗户之前,有人可以建议一种方法吗?
Trying to get my first multi-table MySQL database but i've gut an error I just can wrap my head around. Can someone please suggest an approach before I toss my computer out a window?
我有两个表:
- 客户,其中具有以下行:* id,tourbk_id,tourstart,roomtype1,client_name *
- tourprices ,其中包含以下行:* id,tour_id,tourstart,房间类型,房间价格*
- clients which has rows: *id, tourbk_id, tourstart, roomtype1, client_name*
- tourprices which has rows: *id, tour_id, tourstart, roomtype, roomprice*
目标
我打算在 clients 表中查找以下查询,以查询客户希望购买的游览,比较 client中的游览日期+游览名称+房间类型表,然后回显价格.
Goal
I'm intending for the following query to look, in the clients table for the tour the client wishes to purchase, compare the tour date + tour name + room type in the client table, and echo the price.
$tourquery = "SELECT t.roomprice
FROM clients c, tourprices t
WHERE c.roomtype1 = t.roomtype
AND c.tourstart = t.tourstart
AND c.tourbk_id = t.tour_id";
$tourresult = $db->query($tourquery);
echo '<strong>',"Per room amount: ",'</strong>'.$tourresult. "";
$tourresult->free();
照原样,结果只是一个错误,指出: 可捕获的致命错误:mysqli_result类的对象无法转换为字符串
As-is, the result is just an error stating: Catchable fatal error: Object of class mysqli_result could not be converted to string
非常感谢您的帮助.
推荐答案
query()
函数返回资源,您需要从该函数返回的内容中获取一条记录.查看此页面上的示例,以了解如何从mysql打印数据
The query()
function returns a resource, you'll want fetch a record from what's returned from that function. Look at the examples on this page to learn how to print data from mysql
这篇关于可捕获的致命错误:无法将类mysqli_result的对象转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!