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)


I need to change it to


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'];

//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?



Edited by spivey: trying to make sample URLs not hotlinked

6 Years
Discussion Span
Last Post by rpv_sen

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.

Edited by G&G Designing: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.