Jump to content

[SOLVED] resource id issue


Ninjakreborn

Recommended Posts

I never used some before.

<?php
// this section of php here is made to go ahead and pull out all the deposits
// that this specific user has made, add them up, and formulate a total so we can
// display it on the page as "total deposits"
$deposits = array();
$selectdeposits = "SELECT SUM(amount) FROM transactions WHERE type = 'Deposit' AND userid = '" . $_SESSION['cymember'] . "';";
$totaldeposits = mysql_query($selectdeposits);

?>

Basically when I echo total deposits it throws out Invalid Resource ID #9 or something.

Based on the many examples I looked at this should work.  Originally I had "varchar" as the database type, but tried changing it to "Double." and it's still not working.

 

They are all dollar amounts in the database.

450.00, 400.00, 600.50

obviously it removes the .00 when it's just a flat dollar amount, but it's not adding them up.  Any advice.

Link to comment
Share on other sites

Guest prozente

If this is all of your code then the error is because you haven't connected to MySQL and mysql_query will use the last link opened.

Also what is returned is a resource, there is no need to echo a resource.

Link to comment
Share on other sites

remove the semicolon in the query string.

This is actually a good habit. When you pass a query into sql then it's required to have that after each command (except the last one).

Well in php you are only passing one, so it's a good habit if you ever intend on writing standard sql (like for an install system or something).  So I keep it there for habit, it can never cause negative affects.

 

If this is all of your code then the error is because you haven't connected to MySQL and mysql_query will use the last link opened.

Also what is returned is a resource, there is no need to echo a resource.

This is not all my code, and it's just the part I am having problems with.

 

As far as this problem, I gave up on using sum.  I pulled them all out and did the calculations with PHP.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.