[英]Comparing values of two tables in mysql /php using while and if combination
Is it possible to compare the values from two tables using two while statements. 是否可以使用两个while语句比较两个表中的值。 I was using the following way which didn't work .
我正在使用以下方式不起作用。 Please either point out my mistake or suggest me something easier working solution .
请指出我的错误或建议我一些更容易使用的解决方案。
$sql = "select * from display where gp_no = '$gp_no' ";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0)
{
$s = " select date,member_no from bid where gp_no = '$gp_no ' ";
$r = mysqli_query($conn, $s);
if (mysqli_num_rows($r) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
while($row1 = mysqli_fetch_assoc($r))
{
if($row["member_no"] = $row1[ " member_no"])
{
//some code to display something
} // inner if
} // inner while
} // outer while
} // outer if
} // outermost if
You can also use a different approach. 您也可以使用其他方法。 Something like below :
如下所示:
$array1 = array('1','2','3');
$array2 = array('4','5','3');
foreach($array1 as $index=>$val)
{
if($val == $array2[$index])
{
// go on
}
}
You can try something like this : 您可以尝试这样的事情:
foreach($result as $index=>$val)
{
if($val->member_no == $r[$index]->member_no)
{
// go on
}
}
if($row["member_no"] = $row1[ " member_no"])
if($ row [“ member_no”] = $ row1 [“ member_no”])
==
instead of =
? ==
代替=
?
EDIT: 编辑:
Compares using one while loop, is it better for you? 比较使用while循环,对您来说更好吗? It manage different sized tables:
它管理不同大小的表:
if (mysqli_num_rows($r) > 0)
{
$row_count = mysqli_num_rows($result);
$row1_count = mysqli_num_rows($r);
$remaining_rows = min($row_count, $row1_count);
while($remaining_rows-- > 0)
{
$row = mysqli_fetch_assoc($result);
$row1 = mysqli_fetch_assoc($r);
if($row["member_no"] == $row1["member_no"])
{
//some code to display something
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.