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

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.

Hi

try to update particular URL with help of their database id

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.