Solved

What's wrong with my SQL syntax?

Posted on 2008-10-12
10
255 Views
Last Modified: 2012-05-05
Hello,

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):
http://www.globexposure.net/includes/read.php

Any tips appreciated
0
Comment
Question by:Daniish
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 14

Expert Comment

by:ali_kayahan
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" ;
0
 
LVL 82

Expert Comment

by:hielo
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']}");
0
 
LVL 82

Assisted Solution

by:hielo
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']}");
0
 
LVL 9

Expert Comment

by:mgonullu
ID: 22698175
use mysql_fetch_array instead and try
0
 

Author Comment

by:Daniish
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:
mysql_fetch_array
mysql_fetch_assoc
mysql_fetch_object

None of these have worked.

 What do you suppose i try next?
0
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

by:
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

0
 
LVL 82

Assisted Solution

by:hielo
hielo earned 300 total points
ID: 22746704
What is this:
{locations['reg_id']}

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

Open in new window

0
 

Author Comment

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

handleErrors is not defined
http://www.globexposure.net/index_dubious.php
Line 291

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

www.globexposure.net/index_dubious.php

Obviously not sure why this is happening
0
 
LVL 142

Expert Comment

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

Author Closing Comment

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

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