I have got a table during my SQL Database, and also the table has two fields, one to have an id, and also the other to have an integer. I wish to grab the worthiness within the integer area in which the id is equivalent to a particular number I pass in. The id area is known as "id" and also the integer area is known as "loglevel". This is actually the code I have got, however it does not produce the preferred result.

$result = mysql_query("SELECT loglevel FROM Logs WHERE id='$number'");
echo "Pulled from SQL: " . $result;

The output with this is

Pulled from SQL: Resource id #2

Are you able to assist me to therefore the output is "2" when the value within the SQL table is 2?


You have to fetch your result using [cde], or [cde] (varieties). mysql_fetch_assoc() as came back by mysql_fetch_array(), is really a result resource, no actual rowset:


When you're expecting multiple rows came back as opposed to just one, fetch them in the mysql_query() loop. You will find many good examples of the within the [cde] documentation .

$result = mysql_query("Choose loglevel FROM Logs WHERE id='$number'")

here $outcome is an archive set/ mysql resource not php array. you should utilize mysql_fetch_assoc(), or mysql_fetch_array() to gain access to $result.

$result = mysql_query("SELECT loglevel FROM Logs WHERE id='$number'");

// If the query completed without errors, fetch a result
if ($result) {
  $row = mysql_fetch_assoc($result);
  echo $row['loglevel'];
// Otherwise display the error
else echo "An error occurred: " . mysql_error();

this can print all data in the query.