简体   繁体   English

从查询中获取单个值

[英]Get single value from query

When someone joins a group, i want the creator of the group to get an email.当有人加入一个群组时,我希望该群组的创建者收到一封电子邮件。 So I query the database for the group with that group name and get the email of the group creator.因此,我使用该组名查询组的数据库并获取组创建者的电子邮件。

sql = "SELECT `groupcreatoremail` FROM `userchurch_signup` WHERE `groupname` = '". $groupname . "' limit 1" ;
$result = $conn->query($sql);
$creator_email = "";
while ($fieldinfo=mysqli_fetch_field($result)) {
    $creator_email = $fieldinfo->groupcreatoremail;
}

Based on testing I'm not getting anything even though if i run the SQL statement it works.根据测试,即使我运行 SQL 语句它也能工作,我也没有得到任何东西。

Referenced fetch_assoc about this simple issue.关于这个简单的问题,引用了fetch_assoc I would use their suggested method.我会使用他们建议的方法。 however if you want to know more about the way you selected research on the function you're using.但是,如果您想了解更多关于您选择研究您正在使用的功能的方式。

More info can be found here how to use this information mysqli_fetch_field更多信息可以在这里找到如何使用这个信息mysqli_fetch_field

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "result: " . $row["groupcreatoremail"]. "<br>";
    }
} else {
    echo "0 results";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM