Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

I need proper syntax/procedure for inserting a variable into a SELECT query...

Guest
Apr 02, 2010 Apr 02, 2010

Hello All,

Here's what I want to do:

Take this - $sql = 'SELECT name FROM galleries WHERE spec = XYZ'

where XYZ is a variable passed down from a query string.

What is the proper syntax/procedure for placing a variable in the above statement? I'm trying everything I can think of to no avail.

ADDED:

Maybe more info will be helpful. I only want to pick records out of the 'galleries' table whose 'spec' record is equal to the value of the query string selected on the previous page. Does that make sense? I feel I'm going nuts in the head and may not be explaining myself the best.

Thanks in advance for any help you can offer!

Sincerely,

wordman

TOPICS
Server side applications
265
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 02, 2010 Apr 02, 2010
LATEST

Quit looking, I found it.

This is the part that I was missing. I found it on a php developer forum and just tested it...works perfect!

$sql = "SELECT g_name, g_desc FROM galleries WHERE g_spec = '$spec%' " ;

What I didn't know was that I had to surround the variable in quotes and add the % at the end. Now, I can pull the data from my DB however I like and it works.

I wanted to post this here in case anyone else had a similar hitch.

Many thanks to everyone here for your help!

Cheers,

wordman

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines