0

Is there any reason why this would not return anything?

list($price) = mysql_query(sprintf("select price from product where productid_FK = ".$productid"));

I have used the list function on another page and is working fine, not sure why it is not returning anything on this page.

I have outputted the sql code and ran it in mysql and it worked fine. Please note that this query is in a while loop.

Thanks

3
  • What do you use list() for? Commented Jul 12, 2011 at 1:20
  • Not exactly sure how efficient it is, but is a quick way of getting the result of the query to the var $price. Commented Jul 12, 2011 at 1:40
  • you should provide more complete code... this one line would not only fail to work, but also is very wrong application of list() function. Commented Jul 12, 2011 at 2:35

1 Answer 1

1

mysql_query() returns a ressource, not an array.
You need to use mysql_fetch_array() or similar to get something that list() can work with.

Sign up to request clarification or add additional context in comments.

3 Comments

My apologies I have actually been using mysql_fetch_row around the code which I omitted when copying and pasting. Also tried mysql_fetch_array with no success.
Arrrghhhhhhh my mistake sorry all I made a mistake and put productid_FK instead of productid in my query. Thanks
Here's the code that I am using: list($price) = mysql_fetch_row(mysql_query(sprintf("select price from product where productid = ".$productid"))); Thanks Dr. Molle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.