Php Error Resource Id #4
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn what is resource id in php more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags what is a resource id Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, resource id #5 php helping each other. Join them; it only takes a minute: Sign up Resource id #4 PHP MYSQL up vote -1 down vote favorite $result = mysql_query("SELECT indvsum.sum1 + indvsum.sum2 FROM (SELECT SUM(Cash) AS sum1, SUM(Bank) AS sum2
Php Get Resource Id
FROM players) indvsum"); echo $result; For some reason this is returning Resource id #4. How do I get the results of sum1 + sum2 returned? php mysql share|improve this question edited Jul 8 '12 at 21:10 bostaf 2,40921841 asked May 22 '12 at 15:01 user1307300 7124 1 the question is??? –bitoshi.n May 22 '12 at 15:05 add a comment| 6 Answers 6 active oldest votes up vote 1 down vote This is the expected behavior. resource id #4 curl Please check out the manual for some example about how to fetch rows: mysql_query This is the signature: resource mysql_query ( string $query [, resource $link_identifier = NULL ] ) For getting the rows you should use mysql_fetch_array or mysql_fetch_assoc for example. share|improve this answer answered May 22 '12 at 15:03 Peter Porfy 6,36621837 add a comment| up vote 1 down vote Because that's the standard output of mysql_query function. It returns the identifier related to that query. To get selected rows use mysql_fetch_array($result) or mysql_fetch_row($result) share|improve this answer answered May 22 '12 at 15:04 Akshat Goel 445416 add a comment| up vote 1 down vote Resource id #4 is being returned because $result is an array. As an example: $q_example = "SELECT indvsum.sum1 + indvsum.sum2 AS `aSUM` FROM (SELECT SUM(Cash) AS sum1, SUM(Bank) AS sum2 FROM players) indvsum"; $rsexample = mysql_query($q_example, $DB) or die(mysql_error()); $row_rsexample = mysql_fetch_assoc($rsexample); echo $row_rsexample['aSUM']; ...should get you what you are looking for. share|improve this answer answered May 22 '12 at 15:06 Jason 6,141165195 add a comment| up vote 0 down vote Why dont you just do SELECT SUM(Cash) AS sum1, SUM(Bank) AS sum2 FROM players; Assign the two values in php and then add them. or Use mysql_fetch_row share|improve this answer answered May 22 '12 at 15:05 JHS 5,23611439 add a comment| up vote 0 down vote use mysql_fetch_array $res
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the resource id php mysql company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions
Resource Id #2 Curl
Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million
Resource Id #2 In Php
programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why does this return Resource id #2? [duplicate] up vote 7 down vote favorite 2 Possible Duplicate: How do i http://stackoverflow.com/questions/10704670/resource-id-4-php-mysql “echo” a “Resource id #6” from a MySql response in PHP? I am new at php and SQL and I'm trying to make the php page list the numbers of enries in the table. I'm using this code but it returns Resource id #2: $rt=mysql_query("SELECT COUNT(*) FROM persons"); echo mysql_error(); echo "
Number:
".$rt; php sql mysql share|improve this question asked Jan 25 '11 at 14:55 Charkel 55129 marked as duplicate by MvG, fancyPants, Chris Gerken, http://stackoverflow.com/questions/4794927/why-does-this-return-resource-id-2 Linger, StuartLC Nov 7 '12 at 14:08 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. add a comment| 7 Answers 7 active oldest votes up vote 16 down vote accepted Because you get a mysql ressource when you do a mysql_query(). Use something like mysql_fetch_assoc() to get the next row. It returns an array with the column names as indices. In your case it's probably COUNT(*). Here's a fix and some minor improvements of your snippet: $rt = mysql_query("SELECT COUNT(*) FROM persons") or die(mysql_error()); $row = mysql_fetch_row($rt); if($row) echo "Number:
" . $row[0]; If you need to get all rows of the resultset use this snippet: while($row = mysql_fetch_assoc($rt)) { var_dump($row); } share|improve this answer edited Jan 25 '11 at 15:04 answered Jan 25 '11 at 14:58 svens 7,35052648 add a comment| up vote 3 down vote Try this: $rt=mysql_query("SELECT COUNT(*) FROM persons"); echo mysql_error(); $count = mysql_result($rt, 0, 0); echo $count; share|improve this answer answered Jan 25 '11 at 15:05 Pekkasso 37918 add a comment| up vote 3 down vote In PHP, resources are returned from certain functions so that they can be passed to other related functions. Examples include database connections, database query results, file-handles, etc. According to the docuhere for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us http://stackoverflow.com/questions/11225423/sql-select-query-returning-resource-id-4 Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack http://www.codingforums.com/php/91040-cannot-pull-info-mysql-resource-id-4-a.html Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Sql select query returning Resource id #4 resource id up vote -2 down vote favorite I wrote the following code to select text from database,but when i echo the output it giving output as Resource id #4 mysql_select_db("xxxxx", $link); $q = "SELECT start_of FROM `qr_table` WHERE id_qr =1"; $result = mysql_query ($q, $link); echo $result; i am new to sql,forgive me if its a stupid questain Thanks in advance php sql share|improve this question asked Jun resource id #4 27 '12 at 11:44 kze 225 7 Please, don't use mysql_* functions to write new code. They are no longer maintained and the community has begun deprecation process. See the red box? Instead you should learn about prepared statements and use either PDO or MySQLi. If you can't decide which, this article will help you. If you pick PDO, here is good tutorial. –tereško Jun 27 '12 at 11:47 Also .. please read the manual. –tereško Jun 27 '12 at 11:48 1 @tereško: thats a perfectly valid answer, why did you make it a comment? –Mizipzor Jun 27 '12 at 11:51 1 @mizipzor because, IMHO, it was not a valid answer. I think that any user with 4K+ reputations (thus, with rights to close questions), should put some effort into creating an answer. I actually tend to downvote trivial answers, if they are provided by high-rep users, who are just rep-whoring. –tereško Jun 27 '12 at 22:21 add a comment| 4 Answers 4 active oldest votes up vote 0 down vote accepted you are echoing out the connection. you need to do something with the results like loop through them please check http://www.php.net/manual/en/function.mysql-query.php sha
New? Today's Posts FAQ Rules Guidelines Search Advanced Search Forum :: Server side development PHP Cannot pull info from MySQL - Resource ID #4 - ??? If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Enjoy an ad free experience by logging in. Not a member yet? Register. Results 1 to 3 of 3 Thread: Cannot pull info from MySQL - Resource ID #4 - ??? Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Rate This Thread Current Rating Excellent Good Average Bad Terrible 07-13-2006,03:15 PM #1 Alyson View Profile View Forum Posts New to the CF scene Join Date Jul 2006 Posts 4 Thanks 0 Thanked 0 Times in 0 Posts Cannot pull info from MySQL - Resource ID #4 - ??? Help me!! I'm trying to display one little piece of information from MySQL database and it just doesn't seem to be working properly. It shows a 'Resource ID #4' (sometimes 5 or 6). The database is connecting ok, it doesn't show an error message. Any help anyone can give me would be awesome! Here is my connection file ... db.php (Connection info not shown) $ Reply With Quote 07-13-2006,03:46 PM #2 TheShaner View Profile View Forum Posts Senior Coder Join Date Sep 2005 Location