I am just wondering what is the difference between this query:
$query = "SELECT * FROM users WHERE id='".$_SESSION['mysql_result_id']."'";
and making a variable as this:
$mysql_result_id = $_SESSION['mysql_result_id'];
$query = "SELECT * FROM users WHERE id='".$mysql_result_id."'";
Both are seems similar, but the second one doesn’t work. And also why do I need the concatenation if I just need the value of the session? Lets say the value that is stored in my $_SESSION['mysql_result_id'] is '2', is it just the same as saying id=2? Why do I have to concatenate it? Why can’t I just put "WHERE id=$mysql_result_id"?
You are initializing the variable outside your function
This variable is out of scope for your function while $_SESSION is not. That is why it does not work. Read about PHP Variable Scope here.
If you want method 2 to work then you have to move this
Inside your function ( which you just pasted in your question and then removed )
And to answer your second question : You do not have to wrap numeric values with quotes.