Solved

What's wrong with my SQL syntax?

Posted on 2008-10-12
10
261 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php construct 5 27
Insert won't work due to space in column name 5 22
ebay devID, appID, certID, userToken 2 29
comma true 6 33
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…
The viewer will learn how to count occurrences of each item in an array.

810 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