954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help updating field values

I need to update database table fields that contain URLs based on evaluation of the those URLs. Specifically, I need to eliminate the empty the fields of any URL that contains the directory "img_ours", and I need to take any URL that contain UPCs and change the URL formula, but keep the UPCs.

So if one image url is (these are just examples)

//imagesite.com/images/covers/new/0505/012345678912.gif

I need to change it to

//www.newimagesite.com/images&client=client&upc=012345678912

Here is the code I have come up with

$query = "select image_url from sample_content_type";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$covers = $row['url'];
if($covers){

//explodes the URLs to grab the UPC #
$array = explode('/', $covers);

/*if the value at this point in the array is 'img_ours' I want to delete the URL altogether*/
if($array[4] == 'img_ours'){
         $query = "update content_type_movie_cck set field_cover_value = ''";
         $res1 = mysql_query($query);
}

// if a URL has a UPC, it is always in position 6 in the array, so:
if ( isset($array[6])) {

//strip file extension off images, leaving only the UPC: this bit works
        $dotpos = strpos($array[6],'.');
        $upc = substr($array[6],0, $dotpos);
      
        $query = "update sample_content_type set image_url = 'http://www.newimagesite.com/images&client=client&upc=$upc'";
        $res2 = mysql_query($query);       
}
}


The section updates the field for all records in the table with one value, the full new URL but only one UPC gets added.

I imagine I'm not looping through this stuff properly. Can anyone give me some help?

Thanks

spivey

spivey
Newbie Poster
15 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

The only thing i can think of thats guarrentied to work is using a form..

in textbox 1, enter the orginail url, and in textbox 2, enter the new url. Then replace url 1 with url2

Can't think of doing it any other way that will do them all in 1 shot.

G&G Designing
Junior Poster in Training
90 posts since Aug 2011
Reputation Points: 17
Solved Threads: 11
 

Hi

try to update particular URL with help of their database id

rpv_sen
Junior Poster
178 posts since Mar 2011
Reputation Points: 18
Solved Threads: 16
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: