MYSQL资源查询

时间:2012-01-11 03:04:25

标签: php mysql

我首先从MYSQL数据库中获取查询并通过电子邮件发送到我的邮件

MYSQL

$sqll = "SELECT motheremail FROM family WHERE familyId = 1004";
            $email_message = mysql_query($sqll)or die(mysql_error());;

但是,作为电子邮件中的消息,我得到“资源ID#83”,而不是表格中的内容

任何想法为什么?

2 个答案:

答案 0 :(得分:1)

您需要获取查询结果。

$sqll = "SELECT motheremail FROM family WHERE familyId = 1004";
$result = mysql_query($sqll)or die(mysql_error());

// Fetch the row from the result set
$row = mysql_fetch_assoc($result);

echo $row['motheremail'];

或者如果需要多行,请在while循环中获取它们:

$sqll = "SELECT motheremail FROM family WHERE familyId = 1004";
$result = mysql_query($sqll)or die(mysql_error());

while ($row = mysql_fetch_assoc($result)) {
  echo $row['motheremail'];
}

答案 1 :(得分:0)

mysql_query不会直接返回字符串。你必须使用这样的东西:

$sql = "SELECT `motheremail` FROM `family` WHERE familyId = 1004";
$query = mysql_query($sql) or die (mysql_error());
$message = mysql_fetch_assoc($query)['motheremail'];
echo $message;