问题
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?
Setup
I have two tables:
- clients which has rows: *id, tourbk_id, tourstart, roomtype1, client_name*
- tourprices which has rows: *id, tour_id, tourstart, roomtype, roomprice*
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.
My fubar Query
$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();
As-is, the result is just an error stating: Catchable fatal error: Object of class mysqli_result could not be converted to string
any help is much appreciated.
回答1:
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
来源:https://stackoverflow.com/questions/13020298/catchable-fatal-error-object-of-class-mysqli-result-could-not-be-converted-to-s