加入2 mysqli_query

时间:2018-08-19 21:52:57

标签: php mysql sql mysqli

我正在用SQL进行一些PHP编码,但是我对SQL不太熟悉。我正在使用2 mysqli_query从2个不同的SQL表获取值,但是输出值放置在错误的位置。

for example (this is a simplified example):

Table 1:
Name:Chris
Name: Brad

Table 2:
Country: Canada
Country: USA

我需要输出值为Chris Canada和Brad USA。但是现在我要去克里斯·美国。

下面是我当前的代码:

$result = mysqli_query($link,"Select *,f.floor_no as ffloor,u.unit_no from tbl_add_rent r inner join tbl_add_floor f on f.fid = r.r_floor_no inner join tbl_add_unit u on u.uid = r.r_unit_no where r.branch_id = " . (int)$_SESSION['objLogin']['branch_id'] . " order by r.r_unit_no asc");


$result2 = mysqli_query($link,"Select *,ar.image as r_image,ar.r_name,fl.floor_no as fl_floor,u.unit_no as u_unit,m.month_name from tbl_add_fair f inner join tbl_add_floor fl on fl.fid = f.floor_no inner join tbl_add_unit u on u.uid = f.unit_no inner join tbl_add_month_setup m on m.m_id = f.month_id inner join tbl_add_rent ar on ar.rid = f.rid where f.type = 'Rented' and f.branch_id = " . (int)$_SESSION['objLogin']['branch_id'] . " order by f.f_id desc");

while($row = mysqli_fetch_array($result)  ) {
                    $row1 = mysqli_fetch_array($result2)

//some more code to print row values.
}

我认为问题是代码中$row1 = mysqli_fetch_array($result2)的位置。我尝试为每个mysqli_fetch_array彼此内部运行2 While循环,但这没有用。

是否可以将我拥有的2个mysqli_query合并在一起,而不是将它们分开?即一个$ result = mysqli_query(... etc)

0 个答案:

没有答案