Mysql 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 what is resource id in php workings and policies of this site About Us Learn more about resource id #4 curl Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions what is a resource id Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other.
Resource Id #4 Php
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 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 get resource id 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. 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,35621837 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.su
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies resource id #5 php of this site About Us Learn more about Stack Overflow the company
Resource Id #3 Php
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges
Resource Id Definition
Ask Question x Dismiss Join the Stack 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: http://stackoverflow.com/questions/10704670/resource-id-4-php-mysql Sign up Why do I get “Resource id #4” when I apply print_r() to an array in PHP? [duplicate] up vote 12 down vote favorite 2 Possible Duplicate: How do i “echo” a “Resource id #6” from a MySql response in PHP? Below is the code: $result=mysql_query("select * from choices where a_id='$taskid'")or die(mysql_error()); print_r($result); I get "Resource id #4", any idea? After http://stackoverflow.com/questions/1777801/why-do-i-get-resource-id-4-when-i-apply-print-r-to-an-array-in-php I added while($row=mysql_fetch_assoc($result)) { print_r($row); } I just got [] What's wrong? php mysql arrays share|improve this question edited Feb 17 '12 at 15:40 Charles 40.2k1069107 asked Nov 22 '09 at 4:22 Steven 5,3043481112 marked as duplicate by MvG, Luke Woodward, andrewsi, Ash Burlaczenko, Stijn Geukens Nov 7 '12 at 16:33 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. 2 print_r will only accept arrays and objects. If you use var_dump() it will give you information on whatever you give it. –Ben Shelock Nov 22 '09 at 4:33 add a comment| 4 Answers 4 active oldest votes up vote 20 down vote accepted You are trying to print a mysql resource variable instead of the values contained within the resource it references. You must first try to extract the values you have gotten by using a function such as mysql_fetch_assoc(). You might also try mysql_fetch_array() or mysql_fetch_row(), but I find associative arrays quite nice as they allow you to access their values by the field name
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta http://stackoverflow.com/questions/14744528/mysql-query-returning-resource-id-8-instead-of-desired-value Discuss the workings and policies of this site About Us Learn more http://stackoverflow.com/questions/4290108/how-do-i-echo-a-resource-id-6-from-a-mysql-response-in-php 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 Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping resource id each other. Join them; it only takes a minute: Sign up Mysql query returning resource id #8 instead of desired value [closed] up vote 0 down vote favorite 2 Hi I am trying to discover how to fix my query to return the correct result. Here is my query: $selectShoeRatingQuery = "SELECT cast(round(AVG(rating)*2)/ 2 as decimal(10,1)) FROM resource id #4 rating WHERE shoe_id = '$_GET[id]'"; $shoeRating = mysql_query($selectShoeRatingQuery); The query should return a number with one decimal place (3.5). It works fine when testing in PhpMyAdmin, however on my site it returns resource id #8. The database connection all works fine. php mysql share|improve this question asked Feb 7 '13 at 5:52 enifeder 1811110 closed as not a real question by PeeHaa, j0k, Jocelyn, tereško, Reno Feb 11 '13 at 12:02 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question. add a comment| 6 Answers 6 active oldest votes up vote 7 down vote accepted mysql_query returns a resource. You need to get a row from it: $query = mysql_query($selectShoeRatingQuery); $row = mysql_fetch_row($query); $shoeRating = $row[0]; And, unless you
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 more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack 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 How do i “echo” a “Resource id #6” from a MySql response in PHP? up vote 5 down vote favorite 1 very simple question, i have this: $datos1=mysql_query("SELECT TIMEDIFF(NOW(), '" . $row['fecha'] . "');"); echo($datos1); But the result is: Resource id #6 How can i print the result in the way is meant to be? Thanks! php mysql share|improve this question asked Nov 27 '10 at 4:19 DomingoSL 4,4291163125 1 There is quite a number of duplicates asking essentially the same question. I've voted to close a few of them as duplicates of this one here, as this is among the oldes ones, and phrased in a sufficiently clear and concise fashion to serve as the canonical version. –MvG Nov 7 '12 at 13:50 add a comment| 1 Answer 1 active oldest votes up vote 8 down vote accepted You need to use a fetch function. for example: $result = mysql_query(sprintf("SELECT TIMEDIFF(NOW(), '%s') as time_delta", $row['fecha'])); if($result){ $data = mysql_fetch_assoc($result); echo $data['time_delta']; } However, i wouldnt use the mysql functions unless absolutely necessary. the mysql extension is NOT recommended for use in new projects. Instead you should use PDO with PDO_mysql or mysqli. share|improve this answer edited Nov 27 '10 at 4:37 answered Nov 27 '10 at 4:27 prodigitalson 47.8k36485 1 +1 PDO, not mysqli. Only use mysqli if you are really, really sure that you're going to want to torture yourself with mysql forever and never switch to something else. –El Yobo Nov 27 '10 at 9:26 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the ans