gpt4 book ai didi

php - 嵌套 mysqli_query 没有返回结果

转载 作者:行者123 更新时间:2023-11-29 21:49:30 26 4
gpt4 key购买 nike

在下面的代码中,我需要回显子查询的结果。当我回显$row['email'].'<br>';时 echo 工作正常,我收到了所有电子邮件。

问题在于:

$resultsub.echo $rowb["email"];

为空

问题:我在子查询 $resultsub 中做错了什么?

$result = mysqli_query($conn, "SELECT * FROM wp_mm_email_bounces");

if ($result) {
// output data of each row
while( $row = mysqli_fetch_assoc( $result ) )
{
echo $row['email'].'<br>'; // echo works okay
$resultsub = mysqli_query($conn, "SELECT * FROM `wp_mm_external_emails` WHERE `email` = '". $row['email'] ."' ");
// when I echo this subquery it runs ok. but somehow I get an empty
while( $rowb = mysqli_fetch_assoc( $resultsub) )
{
echo $rowb["email"];
} else {
echo "0 $resultsub";
}
} else {
echo "0 results";
}

最佳答案

我认为你以某种方式搞乱了你的 if-elsewhile 部分。如果我“漂亮地打印”上面的代码片段,它看起来像这样(请参阅我的评论):

<?php
$result = mysqli_query($conn, "SELECT * FROM wp_mm_email_bounces");

if ($result)
{
while( $row = mysqli_fetch_assoc( $result ) )
{
echo $row['email'].'<br>';
$resultsub = mysqli_query($conn, "SELECT * FROM `wp_mm_external_emails` WHERE `email` = '". $row['email'] ."' ");

while( $rowb = mysqli_fetch_assoc( $resultsub) )
{
echo $rowb["email"];
}
else //Where is the corresponding if?
{
echo "0 $resultsub";
}
}
} //I added this enclosing bracket to the if-statement

else //If this is the corresponding else of your first if at the beginning, then you never closed it
{
echo "0 results";
}

?>

关于php - 嵌套 mysqli_query 没有返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33787633/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com