0

How do I fetch an integer value from the database?

$query = mysql_query('select number from table_name where UNIQUE_ID =SOME_UNIQUE_ID');

I am unable to access the integer value using the query above.

3
  • What error did you get? What did you try? Commented Dec 11, 2015 at 8:31
  • are you getting some error? Commented Dec 11, 2015 at 8:34
  • I am not getting any error but the value i want to access don't show up The query is returning no value and i am not familiar with php I am just a beginner. Commented Dec 11, 2015 at 9:08

1 Answer 1

1

As many have commented, it's unclear what is the problem your are facing.

The $query variable you are obtaining is NOT the integer you want but a "query object" (or False if the query failed). You have to extract at least a row using (e.g.) $t=mysql_fetch_array($query). The wanted value will be in $t[0].

Keep in mind, anyway, that the result of a query is tipically a string, so you have to extract its integer value using intval($t[0]).

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

2 Comments

my code is showing error below is my code $src_name = $_GET['source']; $des_name = $_GET['destination']; $src_no_query = mysql_query('SELECT s_no from route201 where s_name =$src_name',$link); $des_no_query = mysql_query('SELECT s_no from route201 where s_name = $des_name',$link); $src_int=mysql_fetch_array($src_no_query); $des_int = mysql_fetch_array($des_no_query); echo "<br>$src_int[0] and $des_int[0]<br>"; Warning: mysql_fetch_array() expects parameter 1 to be resource,boolean given in C:\wamp\www\busmodule\search.php online41
It seems that mysql_query returned False because the query was invalid. Try putting quotes around variables values, like this: $src_no_query = mysql_query('SELECT s_no from route201 where s_name ="$src_name"',$link);

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.