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 6217449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:25:43+00:00 2026-05-24T07:25:43+00:00

heres my code: function toAscii($str, $replace=array(), $delimiter=’-‘) { if( !empty($replace) ) { $str =

  • 0

heres my code:

function toAscii($str, $replace=array(), $delimiter='-') {
    if( !empty($replace) ) {
        $str = str_replace((array)$replace, ' ', $str);
    }

    $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
    $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
    $clean = strtolower(trim($clean, '-'));
    $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);

    return $clean;
}

$sql = mysql_query("select * from cities_dev order by PostalCode asc") or die(mysql_error());

// id, id_province, id_city, postal_code, latitude, longitude

while ($row = mysql_fetch_assoc($sql))
{
    $slug = toAscii($row['City']);
    $id_province = mysql_result(mysql_query("select id from provinces where abbr='".mysql_real_escape_string($row['ProvinceCode'])."'"), 0) or die($row['City'].' - prov');
    $id_city = mysql_result(mysql_query("select id from cities where slug='".$slug."' and id_province='".$id_province."'"), 0) or die($id_province . ' - ' . $row['City'] .' - ' . $row['PostalCode'] . ' - city');
    $postal_code = mysql_real_escape_string($row['PostalCode']);
    $latitude = mysql_real_escape_string($row['Latitude']);
    $longitude = mysql_real_escape_string($row['Longitude']);

    mysql_query("insert into geo (`id_province`, `id_city`, `postal_code`, `latitude`, `longitude`) 
                 values ('$id_province', '$id_city', '$postal_code', '$latitude', '$longitude')") or die('insert');
}

what i am trying to do is insert a new row for each postalcode/lat/lng row. there are about 750,000 rows. i need to grab the province ID and city ID from 2 other tables for each new row inserted.

this sql works, but is taking FOREVER. can anyone show me a better way of coding this?

  • 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-05-24T07:25:44+00:00Added an answer on May 24, 2026 at 7:25 am

    I don’t think any of the other suggestions will really help you speed this up..

    You can change this entire thing into a INSERT … SELECT query. There’s plenty of documentation on how to do this. The select itself will be slow if there’s a lot of postal codes, but if you are using InnoDB, have good a good amount for the page buffer size (global setting) so all the data will fit in memory, this should help quite a bit.

    MyISAM can also be very slow for inserts, so I would also recommend changing the second table to InnoDB if you haven’t already.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So heres the basic outline function x(){ // some code function y(){ //some more
heres my code: $('#approve').click(function(){ var p_id=$('#propid').val(); var para={ pid_r:p_id }; var postdata=$.param(para)+'&'+$('[name=scripts[]]:checked').serialize(); $.ajax({ type:POST,
Here is my code: function pauseSound() { var pauseSound = document.getElementById(backgroundMusic); pauseSound.pause(); } I
I am completely stumped. Here is my php (CodeIgniter) code: function mod() { $uid
p2 = setInterval(function () { clearInterval(p2); some code here; }, waitTime) I need to
Trying to truncate some code here and running into a problem: <script type=text/javascript> $(function()
This my jquery function, function getRecordspage(curPage, pagSize) { // code here $(.pager).pagination(strarr[1], { callback:
Here is the code: $('#sousmenu a').click (function (){ startSlideshow(<?php echo json_encode(glob(photos- .$_GET[folder]. /*.jpg));?>); return
Here is my code: var showNo = 1; window.setInterval(function() { console.log(showNo); if(showNo === 1)
Here's my Zend code: <?php require_once ('Zend\Form.php'); class Sergio_Form_registrationform extends Zend_Form { public function

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.