Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8682901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:53:53+00:00 2026-06-12T21:53:53+00:00

Hi I have a postcode database which contains postcodes and the lat and lon

  • 0

Hi I have a postcode database which contains postcodes and the lat and lon details, In another table i have a list of companies with postcodes and want to add the lat and lon details to matching postcodes, rather than use a join query etc. Below is the code i am using, i have used something similar before, but i just can not work out why this isn’t working.

$host    = "localhost";
$username = "";
$password = "";
$database = "";
mysql_connect( $host, $username, $password );
mysql_select_db( $database ) or die( "Unable to select database" );


$query = "SELECT * FROM postcodes";      
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){   



$postcode = $row['postcode'];   
$lat = $row['lat']; 
$lon = $row['lon']; 



$result = mysql_query("UPDATE companies SET lat ='$lat' and lng ='$lon'  
WHERE postal_code = '$postcode'") 
or die(mysql_error());  

}

The error I am getting is: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/visitrac/public_html/postcode.php on line 15

if i move the closed bracket so it is before the update then the error goes but no information gets into the database, which i assume is because it is out of the loop. I have tried all sorts of things but nothing seems to work and so any nudges in the right direction would be appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:53:54+00:00Added an answer on June 12, 2026 at 9:53 pm

    There’s really no need for the loop through the postcode results. You can update all companies in a single SQL statement.

    UPDATE companies c
        INNER JOIN postcodes p
            ON c.postal_code = p.postcode
        SET c.lat = p.lat,
            c.lng = p.lon
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Postcode in my large database, which contains values like SL5 9JH, LU1
I have a table of names and addresses, which includes a postcode column. I
Hi I have a database with a list of contacts in which I am
I have 2 tables in my database, Companies & Users. I have one list
Scenario. Simple database which has a list of addresses addressID FirstName LastName City PostCode
I have a table of contacts and a table of postcode data. I need
I have created a PHP form which requires the user to select a postcode
I need to re-format a list of UK postcodes and have started with the
I have a javascript regex which validates UK postcodes. It works well, but it
I have recently noticed that our product has incorrect postcode locations (lat & long

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.