Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What's wrong with my SQL syntax?

Posted on 2008-10-12
10
Medium Priority
?
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1200 total points
ID: 22698171
or mayby id:
$lreg = mysql_query("SELECT lat,lng,maxzl,icon FROM regions WHERE id = {locations['reg_id']}");
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
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 dynamically set the form action using jQuery.

704 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