我写了这段代码
$serial_no = 1;
while($rowss = mysqli_fetch_array($selectQuery))
echo $rowss['work_date'];
$mauzaNameQry = mysqli_query($conn,"select moza_name from moza_names where mauza_id =1");
echo mysql_error();
$mauzaNameRslt = mysqli_fetch_array($mauzaNameQry);
`echo $rowss['work_date'];
`
当我写了另一个select内部循环查询时,它没有返回$ rowss []数组中的任何内容,因为我已经在上面写了选择查询内部while循环,它从moza_name表中选择数据。如果删除moza_name表的内部查询,$ rowss []会显示数据。它甚至没有显示任何错误。
答案 0 :(得分:0)
我不确定你要做什么,但这可能是吗?
<?php
$serial_no = 1;
while($row = mysqli_fetch_array($selectQuery)) {
echo $row['work_date'];
}
$mauzaNameQry = mysqli_query($conn,"SELECT moza_name FROM moza_names WEHRE `mauza_id`='1'") or die(mysqli_error($mauzaNameQry));
while($row = mysqli_fetch_array($mauzaNameQry)) {
echo $row['work_date'];
}
?>
更新:
您是否尝试进行嵌套循环?
<?php
$serial_no = 1;
while($rowss = mysqli_fetch_array($selectQuery)) {
echo $rowss['work_date'];
$mauzaNameQry = mysqli_query($conn,"SELECT moza_name FROM moza_names where `mauza_id`='1'") or die();
while($mauzaNameRslt = mysqli_fetch_array($mauzaNameQry)) {
echo $mauzaNameRslt['work_date'];
}
}
?>
更新3:
<?php
$userId = 1; //ID to search for
$ID = mysqli_query($conn,"SELECT * FROM work_sheet where `mauza_id`='$userId'") or die(); //get ID and if it doesn't exist, exit
$IdFromTable1 = $ID['moza_id']; // set the correct ID from table1
$mauzaNameQry = mysqli_query($conn,"SELECT * FROM moza_names where `mauza_id`='$IdFromTable1'") or die(); //check for table1's correct ID on table2
echo $mauzaNameRslt['moza_name']; //echo the name from table1's ID
?>