Possible Duplicate:
How do i “echo” a “Resource id #6” from a MySql response in PHP?




我正在从查询中寻找结果,但是它一直给我提供资源ID#3。

以下是我的代码。

$type = "SELECT `sellingid` FROM `ticket` WHERE `ticketid` = $_GET[ticketid]";
$typeResult = mysql_query($type);

print_r($typeResult);


我在这里错过了哪一步?

最佳答案

您需要获取结果。您要做的就是发送查询。

请注意,如果要编写新代码,则应使用mysqli_PDO函数,因为查询容易受到SQL注入的攻击,而mysql_函数则是being deprecated。犹豫的是,下面是mysql_fetch_assoc的示例。

<?php

$sql = "SELECT `sellingid` FROM `ticket` WHERE `ticketid` = $_GET[ticketid]";

$result = mysql_query($sql);

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
//       then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_assoc($result)) {
    echo $row[sellingid];
}

mysql_free_result($result);

?>


Reference

关于php - 从查询中获取结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13075568/

10-12 12:26
查看更多