鉴于此代码:
<?php
include 'dbconnect.php';
include 'properties_classes.php';
mysqli_select_db($connection, 'bl1property');
$p_results = mysqli_query($connection, "SELECT * FROM property");
$r_results = mysqli_query($connection, "SELECT * FROM rooms");
function return_bed_results($p_id, $r_results) {
$total_bed = 0;
$available_single_bed = 0;
$available_double_bed = 0;
echo ' Start searching for rooms at property ' . $p_id . '</br>';
while ($bed_r = mysqli_fetch_array($r_results)) {
echo 'str from ' . $bed_r['property id'] . '</br>';
if ($p_id == $bed_r['property id']){
echo 'pass (1) ' . $bed_r['property id'] . ' n ' . $bed_r['room no'] . '</br>';
if ($bed_r['occupied'] == 0) {
echo 'pass (2) ';
if ($bed_r['room type'] == 'Single') {
echo ' single ' . '</br>';
$available_single_bed++;
} else {
echo ' double ' . '</br>';
$available_double_bed++;
}
}
$total_bed++;
}
}
$return_b = new BedResults;
$return_b->total_no_beds = $total_bed;
$return_b->available_single_beds = $available_single_bed;
$return_b->available_double_beds = $available_double_bed;
echo '</br>' . 'Property no ' . $p_id . '</br>';
echo 'No of beds = ' . $return_b->total_no_beds . '</br>';
echo 'No of S beds = ' . $return_b->available_single_beds . '</br>';
echo 'No of D beds = ' . $return_b->available_double_beds . '</br>';
return $return_b;
}
$p_search_index = 0;
$newResults[] = new Results;
while ($row = mysqli_fetch_array($p_results)) {
if ($accomodation_type == $row['tenant type'] || $accomodation_type == 'any') {
if ($living_arrangment == $row['arrangement'] || $living_arrangment == 'any') {
if ($min_sel <= $row['rent_min'] && $max_sel >= $row['rent_max']) {
$b_total = return_bed_results($row['id'], $r_results);
$newResults[$p_search_index] = new Results;
$newResults[$p_search_index]->total_Bed = $b_total->total_no_beds;
$newResults[$p_search_index]->available_single = $b_total->available_single_beds;
$newResults[$p_search_index]->available_double = $b_total->available_double_beds;
$newResults[$p_search_index]->rent_min = $row['rent_min'];
$newResults[$p_search_index]->rent_max = $row['rent_max'];
$p_search_index++;
}
}
}
}
?>
第一个循环工作,它给了我数据,但之后......没有什么事情发生!!
这是输出结果:
从1 pass(1)1 n 1 str开始搜索1 str的房间 从1遍(1)1 n 2 str从1遍(1)1 n 3遍(2)双str 从1遍(1)1 n 4 str从1遍(1)1 n 5 str从1遍(1)1 n 2 str从2 str从2 str从2 str从2 str从3 str从3 str str 3 str,3 str,4 str,4 str,4 str,4 str,4 str 从7 str,7 str,7 str,7 str,7 str,7 str,7 str,7 str 8 str,8 str,8 str,8 str,8 str,8 str,8 str,8 str
物业编号1床位数= 6 S床数= 0 D床数= 1开始 寻找物业3的房间
物业编号3床位数= 0 S床数= 0 D床数= 0开始 在4号房间寻找房间
物业编号4床位数= 0 S床数= 0 D床数= 0开始 寻找物业7的房间
物业编号7床位数= 0 S床数= 0 D床数= 0开始 在8号房间寻找房间。
物业编号8床位数= 0 S床数= 0 D床数= 0
我不知道为什么只有第一个循环有效......有人可以帮助我 的由于
答案 0 :(得分:0)
第一次循环后是否可能重置连接? 您可能必须为第二个查询重新打开它。
请你发布你的dbconnect.php(当然是模糊的)
编辑:当你添加另一个像这样的mysqli_select_db语句时会发生什么?
mysqli_select_db($connection, 'bl1property');
$p_results = mysqli_query($connection, "SELECT * FROM property");
mysqli_select_db($connection, 'bl1property');
$r_results = mysqli_query($connection, "SELECT * FROM rooms");
答案 1 :(得分:0)
你为什么这样做:
mysqli_select_db($connection, 'dbname');
试试这个:
$connection = mysqli_connect('localhost','root','password','dbname');
如果您的密码什么都没有,那么您必须写入NULL。