Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9158779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:19:49+00:00 2026-06-17T13:19:49+00:00

I am just wondering what is the difference between this query: $query = SELECT

  • 0

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"?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:19:50+00:00Added an answer on June 17, 2026 at 1:19 pm

    You are initializing the variable outside your function

    $mysql_result_id = $_SESSION['mysql_result_id'];
    

    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

    $mysql_result_id = $_SESSION['mysql_result_id'];
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering what the difference is between these two and what the benefit for
Just wondering about this one : Whats the difference, or is there a difference
just wondering what the subtle difference between an array and a range is. I
Quite curious, but was just wondering if anyone knows the difference between using: System.Windows.Forms.SaveFileDialog
Just wondering what the difference between MFC control messages prefixed with the following is:
Just wondering is it possible to build CLI app that can be run from
Just wondering if anyone can optimize this usortMonths() function to be better? Basically I
I was wondering what the difference between BigInt , MediumInt , and Int are...
I'm learning Java, coming from C and I found an interesting difference between languages
Possible Duplicate: C++ equivalent of instanceof I was wondering what the difference between dynamic_cast

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.