What's wrong with my SQL syntax?

Posted on 2008-10-12
Last Modified: 2012-05-05

I have written the following SQL query to find the local region:
$lreg = mysql_query("SELECT lat,lng,maxzl,icon FROM regions WHERE locations['reg_id']");

and i'm using the following to process the results:
// this displays the local Regional marker
while ($row=mysql_fetch_object($lreg)){
      echo '<reg_local lat="'.$row['lat'].'" lng="'.$row['lng'].'" maxzl="'.$row['maxzl'].'" icon="arrow"/>';

Can't for the life of me see what's wrong but Firebug reports the following regarding the line beginning 'While':
:  mysql_fetch_object(): supplied argument is not a valid MySQL result resource

You can see this here (line 66):

Any tips appreciated
Question by:Daniish
  • 3
  • 3
  • 2
  • +2
LVL 14

Expert Comment

ID: 22698163
  Your WHERE clause is typed in a wrong way , you are not making any kind of comparisions on there it should be something like ;

   WHERE locations['reg_id'] = "Some number" ;
LVL 82

Expert Comment

ID: 22698167
your where clause is missing "fieldName=".  Do you have a field named "reg_id"? If so, try:
$lreg = mysql_query("SELECT lat,lng,maxzl,icon FROM regions WHERE reg_id = {locations['reg_id']}");
LVL 82

Assisted Solution

hielo earned 300 total points
ID: 22698171
or mayby id:
$lreg = mysql_query("SELECT lat,lng,maxzl,icon FROM regions WHERE id = {locations['reg_id']}");

Expert Comment

ID: 22698175
use mysql_fetch_array instead and try

Author Comment

ID: 22739514
Sorry for the delay in getting back to you...

I have changed the WHERE clause to:
$lreg = mysql_query("SELECT lat,lng,maxzl,icon FROM regions WHERE {locations['reg_id']} = id");

and i have tried using:

None of these have worked.

 What do you suppose i try next?
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

LVL 142

Accepted Solution

Guy Hengel [angelIII / a3] earned 200 total points
ID: 22739770
you did open a connection, did you?
also, try to get the actual mysql error:

$lreg = mysql_query("SELECT lat,lng,maxzl,icon FROM regions WHERE {locations['reg_id']} = id") or die(mysql_error());

Open in new window

LVL 82

Assisted Solution

hielo earned 300 total points
ID: 22746704
What is this:

Most likely you meant:
$lreg = mysql_query("SELECT lat,lng,maxzl,icon FROM regions WHERE {$locations['reg_id']} = id");

Open in new window


Author Comment

ID: 22747657
When this MySQL query is included in my read file it causes Firebug to report this problem:

handleErrors is not defined
Line 291

I have created a development version of the site & read file, where you can see this:

Obviously not sure why this is happening
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22747685
I opened the page without any errors?!

Author Closing Comment

ID: 31505465
Not sure what occurred with regards to the error i was getting but your support was very helpful.

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now