Jump to content

PHP to update postcodes in a table with a space.


mackin

Recommended Posts

I have a table of Postcodes - some of them have no spaces between Outcode and Incode i.e LA138UT instead of LA13 8UT.

 

I need a php code to search the column for no spaced postcodes, and insert a space 3 characters from the end of the postcode string.

 

I have this code to insert the space

if (strpos($str, ' ')===false){ //no space
   $str = substr_replace($str, ' ', -3, 0); //insert space
}

and i can make it work one postcode at a time using a form, but I want to run the script and it will update them all.

 

Any advice ?

Link to comment
Share on other sites

trying to do it like this but the update function isnt correct

if (strpos($row_update_postcodes['est_postcode'], ' ')===false){ //no space
   $row_update_postcodes['est_postcode'] = substr_replace($row_update_postcodes['est_postcode'], ' ', -3, 0); //insert space
}

mysql_select_db($database_contractors, $contractors);
$query_update_postcodes2 = "UPDATE hotels SET est_postcode = "$row_update_postcodes['est_postcode']" WHERE id = "$row_update_postcodes['id']")";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.