0

EDITed and explain in full details

I working with a project with this scenario.

Each user has a "UID" which is unique ID.

They can add their own "item_option_name" and "item_option_value".

"item_option_name" is not allowed to be duplicated but "item_option_value" is allowed.

database_table

enter image description here

update_mysql

public function update_option($uid,$oid,$item_option_name,$option_value){

    $sql_check="SELECT * FROM options where uid='$uid' and item_option_name='$item_option_name'";

    if($this->conn->row_count($sql_check)==true){
        return false;
    }else{
        $sql = "UPDATE options SET item_option_name='$item_option_name', item_option_value='$option_value' WHERE oid='$oid'";
        $this->conn->update($sql);
        return true;
    }

}   

When i submit the form, Update function will work if i change item_option_name to something else. It won't work if item_option_name remain unchanged.

Example 1. If i want to update Size

item_option_name=Size_new
item_option_value ="large,extra large" 

and then submit form. It works fine

Example 2.

item_option_name=Size
item_option_value ="large,extra large" 

and then submit form. item_option_name remains same. It won't work due to "Size" already exist.

Anyone know how to fix this issue?

gosulove
  • 1,645
  • 2
  • 26
  • 40
  • inside your update function write simply: `"UPDATE options SET item_option_name='new_item_option_name',item_option_value='$option_value' WHERE uid='$uid' and item_option_name='$item_option_name'`your update is not working as you set 'item_option_name' by the same value – Dipanwita Kundu Sep 30 '16 at 08:37
  • Is it worth mentioning normalisation at this point? – Strawberry Sep 30 '16 at 08:43
  • let me guess, you like `find_in_set()` ... which won't use indexes – Drew Sep 30 '16 at 08:46
  • @DipanwitaKundu I think i didn't explain well for my question. Please check , i have updated the new content. – gosulove Sep 30 '16 at 09:04
  • @Strawberry I think i didn't explain well for my question. Please check , i have updated the new content. – gosulove Sep 30 '16 at 09:05
  • @Drew I think i didn't explain well for my question. Please check , i have updated the new content. – gosulove Sep 30 '16 at 09:05
  • As per your example 2, you will not able to reach the update query because, "$this->conn->row_count($sql_check)" will return true. so you need to change your update function. – Dipanwita Kundu Sep 30 '16 at 09:14
  • @DipanwitaKundu yes i know the problem is here. But in order to fulfill my purpose, I not sure how to modify the coding – gosulove Sep 30 '16 at 09:16
  • Only write your update query inside your update function: `"UPDATE options SET item_option_name='new_item_option_name',item_option_value='$‌​option_value' WHERE uid='$uid' and item_option_name='$item_option_name'` Update will execute only when match will find – Dipanwita Kundu Sep 30 '16 at 09:18

0 Answers0