Solved

What's wrong with my SQL syntax?

Posted on 2008-10-12
10
262 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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
 
LVL 143

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 143

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

820 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