需要来自DB的数据而不是资源ID

时间:2014-04-21 06:41:55

标签: php mysql

我一直在使用stackoverflow.com一段时间来回答问题,但这是我第一次发帖。提前谢谢!

我正在尝试获取与此查询相关联的实际数字:

$purchasenumber = mysql_query("SELECT `purchase_order_number` FROM `purchaseorder` ORDER BY `purchase_order_number` DESC LIMIT 1");
echo $purchasenumber;

我收到“资源ID#”而不是实际数字。

然后,我想使用检索到的数字从数据库中提取更多数据。我实际上是在创建一个可打印的页面,其中包含数据库中两个表的信息。

$result = mysql_query("SELECT * FROM purchaseorder, customers WHERE purchase_order_number = $purchasenumber AND purchaseorder.customer_ID = customers.customer_ID");
while ($row = mysql_fetch_assoc($result)) {}    

有人有任何想法将资源ID转换为实际数据吗?我可能会以错误的方式解决这个问题,如果我是,请告诉我!

感谢。

2 个答案:

答案 0 :(得分:1)

您需要使用mysql_fetch_array()从mysql_query获取数据:

    $result = mysql_query("SELECT `purchase_order_number` FROM `purchaseorder` ORDER BY `purchase_order_number` DESC LIMIT 1");
    $data = mysql_fetch_array($result);
    $purchasenumber = $data['purchase_order_number'];

More Info可以在PHP.net上找到

答案 1 :(得分:1)

谢谢,kimbarcelona。你的回复有效。

$result = mysql_query("SELECT `purchase_order_number` FROM `purchaseorder` ORDER BY `purchase_order_number` DESC LIMIT 1");
$data = mysql_fetch_array($result);
$purchasenumber = $data['purchase_order_number'];

然后我只是为下一个结果使用了另一个变量

$result2 = mysql_query("SELECT * FROM purchaseorder, customers WHERE purchase_order_number = $purchasenumber AND purchaseorder.customer_ID = customers.customer_ID");
while ($row = mysql_fetch_assoc($result2)) {}

再次感谢您的回复!