select查询不起作用

vu8f3i0k  于 2021-06-20  发布在  Mysql
关注(0)|答案(4)|浏览(295)
$sql = "SELECT temail FROM teacherusers WHERE tfullname='$teachername' limit 1";
 $result = mysql_query($sql);
 $value = mysql_fetch_object($result);
 $teacheremail2 = $value->temail;
 echo $teacheremail2;
``` `echo $teacheremail2` 不返回任何内容。 `$teachername` 是有效的,我检查过多次。
csbfibhn

csbfibhn1#

结果 mysql_fetch_object($result) 是一个对象(stdclass)。
解释 object(stdClass) 我可以在这个链接上找到

$sql = "SELECT temail FROM teacherusers WHERE tfullname='$teachername' limit 1";
$result = mysql_query($sql);
while ($value = mysql_fetch_object($result))
    {
    $teacheremail2 = $value->temail;
    echo $teacheremail2;
    }
uz75evzq

uz75evzq2#

首先,您需要直接对数据库运行查询,以确保查询返回某种结果。第二,如果可以的话,你需要直接回显$value来检查你是否在网页上得到了结果。
然后可以检查temail是否是$value字段

8hhllhi2

8hhllhi23#

$sql = "SELECT temail FROM teacherusers WHERE tfullname='$teachername' limit 1";
 $result = mysql_query($sql);
while ($value = mysql_fetch_object($result))
    {
    $teacheremail2 = $value->temail;
    echo $teacheremail2;
    }

希望这有帮助

z9smfwbn

z9smfwbn4#

你需要一个二维数组 $value[0]->temail

相关问题