This topic is locked
[SOLVED]

 How can I delete data in a field if another field is updated

1/2/2020 5:54:08 AM
PHPRunner General questions
M
mhollibush author

What I have:

I have over 8000 old images in "thumb_med" column of a table

I created a new "new_pic" column in the table.
I would like to delete the data in the "thumb_med" when the "new_pic" is added.
Logic behind this.

On the view page I need like to keep the "thumb_med" visible until a "new_pic" is added.

Once the "new_pic" is added, the "thumb_med" should be empty and not displayed ( hide empty fields )
Looking for guidance on how to accomplish this in the "before recorded added" event

A
acpan 1/2/2020

Try this:
>I have over 8000 old images in "thumb_med" column of a table

>I created a new "new_pic" column in the table.

>I would like to delete the data in the "thumb_med" when the "new_pic" is added.
Before add event:
// Make the thumb_med field empty when adding new_pic:



$values["thumb_med] = "":


then on the view page, choose which field to display image:



// if thumb_med is empty, it means new_pic must be updated, use the new_pic

if ($data["thumb_med"] == "" )

{

$value = $data["new_pic"];

}

else

{

$value = $data["thumb_med"];

}


Note: in events, you use $values["your_field"] to write new value to the field in the db;

in view page, you use $value, which is the current field you want to display.
ACP

M
mhollibush author 1/2/2020



Try this:
>I have over 8000 old images in "thumb_med" column of a table

>I created a new "new_pic" column in the table.

>I would like to delete the data in the "thumb_med" when the "new_pic" is added.
Before add event:
// Make the thumb_med field empty when adding new_pic:



$values["thumb_med] = "":


then on the view page, choose which field to display image:



// if thumb_med is empty, it means new_pic must be updated, use the new_pic

if ($data["thumb_med"] == "" )

{

$value = $data["new_pic"];

}

else

{

$value = $data["thumb_med"];

}


Note: in events, you use $values["your_field"] to write new value to the field in the db;

in view page, you use $value, which is the current field you want to display.
ACP


Thanks for the quick response.

My concern ( if there should be one )

Before the add event:



$values["thumb_med] = "":



If the "new_pic" is not added ( not required )

wouldn't that still empty the "thumb_med" ?
I don't want the "thumb_med" to be removed unless the "new_pic" is updated.
again with "novice" issues <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=89771&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

A
acpan 1/2/2020

> I don't want the "thumb_med" to be removed unless the "new_pic" is updated.
Yes, valid concern.
Before add events, check if the new_pic is added.

We do this by checking if the new_pic field has any NEW data by checking its length:
If (strlen($values["new_pic"]) > 0 )

{

// Make the thumb_med field empty when adding new_pic:

$values["thumb_med] = "";

}
ACP

M
mhollibush author 1/2/2020



> I don't want the "thumb_med" to be removed unless the "new_pic" is updated.
Yes, valid concern.
Before add events, check if the new_pic is added.

We do this by checking if the new_pic field has any NEW data by checking its length:
If (strlen($values["new_pic"]) > 0 )

{

// Make the thumb_med field empty when adding new_pic:

$values["thumb_med] = "";

}
ACP


WORKS AS DESCRIBED!!!!! Thank You!!!



// pull Thumbpic path from uploaded picture

$fileArray = json_decode($values["new_pic"],true);
$image_name_with_path = $fileArray[0]['name'];

$image_name_only = $fileArray[0]['usrName'];

$thumbnail_with_path = $fileArray[0]['thumbnail'];
$values["thumbpic"] = $thumbnail_with_path;
//Check If New Picture has Been Added

If (strlen($values["new_pic"]) > 0 )

{

// Make the thumb_med field empty if new picture added

$values["thumb_med"] = "";

}
A
acpan 1/2/2020

Glad you find the rope. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=89774&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />
ACP