As a beginner sql, I also spent a lot of time trying to use these one-dimensional sql query results directly. I thought that since the result is not an array, I could skip these while-loops with these fetch_arrays.
However, only now I understand that although the result can be an integer value of 8, if you do not convert it to the value that it is, it is still considered simply a “query result” instead of an integer.
Jonathan's code helped me figure this out. For myself, I used a slightly different code that helped me. Here is what worked for me:
$con=mysql_connect("host", "user", "password"); if(!$con) {die('could not connect: '.mysql_error()); } $db_selected=mysql_select_db("database", $con); $sql = "the sql query that yiels one value, for example a SELECT COUNT query"; $outcome_considered_as_a_query-result-set = mysql_query($sql,$con); $outcome_considered_as_the_one_element_of_the_result_set = mysql_result($outcome_considered_as_a_query-result-set,0); echo $outcome_considered_as_the_one_element_of_the_result_set; mysql_close($con);
source share