Advertisement:

Author Topic: Replace word  (Read 949 times)

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Replace word
« Reply #15 on: March 20, 2019, 12:31:36 pm »
@patrickFromCroatia
I tested your code but it really didn't work!
I edited my first post for clarifying my question!
Thanks,

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Replace word
« Reply #16 on: March 21, 2019, 05:22:16 pm »
I will try the code on my demo site.

One suggestion: please don't expect EVERYTHING from others, try enabling PHP debugging, SQL debugging, testing, looking at tutorials etc. That way you will learn and it will be better than just copying the code.

Regards.

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Replace word
« Reply #17 on: March 21, 2019, 05:30:57 pm »
Just tried the code. It worked.

http://148.251.207.178/osclass/plugins/demo/index.php?page=item&id=102

I selected "red" and "red_color" was saved in the database.

Regards.

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Replace word
« Reply #18 on: March 21, 2019, 07:44:20 pm »
Just tried the code. It worked.

http://148.251.207.178/osclass/plugins/demo/index.php?page=item&id=102

I selected "red" and "red_color" was saved in the database.

Regards.

Not like that. Please reread my first post. I edited it!
I dont want just replace red with red_color. I want to add "_color" to the value of custom-field. And also for multiple custom-fields not just one. Please read my first post again. Its edited!
Thank you Patrick,

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Replace word
« Reply #19 on: March 26, 2019, 11:33:43 pm »
Just tried the code. It worked.

http://148.251.207.178/osclass/plugins/demo/index.php?page=item&id=102

I selected "red" and "red_color" was saved in the database.

Regards.

Not like that. Please reread my first post. I edited it!
I dont want just replace red with red_color. I want to add "_color" to the value of custom-field. And also for multiple custom-fields not just one. Please read my first post again. Its edited!
Thank you Patrick,

@patrickFromCroatia
Patrick, did you read this post?

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Replace word
« Reply #20 on: March 28, 2019, 04:44:13 pm »
Look, I can help but I can't write all the code. You have a lot of questions and expect people to write all the code for you. There's a job section for that. I work on a lot of paid projects and I don't have time, can't and don't want to do everything in cases like this...

Anyways, make an array of colors and use foreach to replace each one of them, or look if there is a SQL query to replace more stuff, I have no idea. Not sure how fast is this, but it probaby can be optimized...

Code: [Select]
<?php
function wm_item_post_replace_meta_value($item) {
    
$field_id 5// CUSTOM FIELD ID
    
$item_id $item['pk_i_id']; // Get item ID.
    
$dao = new DAO(); // Intialise data access object.
    
$colors = array('red''blue'); // List of colors.
    
foreach($colors as $color) {
        
$query sprintf('UPDATE %st_item_meta SET s_value = "%s-color" WHERE fk_i_item_id = %s AND fk_i_field_id = %s AND s_value = "%s"'DB_TABLE_PREFIX$color$item_id$field_id$color); // Update.
        
$dao->dao->query($query);
    }
}
osc_add_hook('posted_item''wm_item_post_replace_meta_value');

Regards.

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Replace word
« Reply #21 on: March 28, 2019, 11:20:27 pm »
Look, I can help but I can't write all the code. You have a lot of questions and expect people to write all the code for you. There's a job section for that. I work on a lot of paid projects and I don't have time, can't and don't want to do everything in cases like this...

Anyways, make an array of colors and use foreach to replace each one of them, or look if there is a SQL query to replace more stuff, I have no idea. Not sure how fast is this, but it probaby can be optimized...

Code: [Select]
<?php
function wm_item_post_replace_meta_value($item) {
    
$field_id 5// CUSTOM FIELD ID
    
$item_id $item['pk_i_id']; // Get item ID.
    
$dao = new DAO(); // Intialise data access object.
    
$colors = array('red''blue'); // List of colors.
    
foreach($colors as $color) {
        
$query sprintf('UPDATE %st_item_meta SET s_value = "%s-color" WHERE fk_i_item_id = %s AND fk_i_field_id = %s AND s_value = "%s"'DB_TABLE_PREFIX$color$item_id$field_id$color); // Update.
        
$dao->dao->query($query);
    }
}
osc_add_hook('posted_item''wm_item_post_replace_meta_value');

Regards.

@patrickFromCroatia
Thank you very much, this works now! but there is one problem! i want to add '-color' to custom-field's value! i want to get the value of custom-field and add '-color' to it!
please see this code:
Code: [Select]
<?php
function wm_item_post_replace_meta_value($item) {
    
$field_id 5;
    
$item_id $item['pk_i_id'];
    
$dao = new DAO();
    
$cf_value Params::getParam('meta[24]'); //Not working! i can not get the value of custom-field!
$query sprintf('UPDATE %st_item_meta SET s_value = "%s-color" WHERE fk_i_item_id = %s AND fk_i_field_id = %s'DB_TABLE_PREFIX$cf_value$item_id$field_id);
$dao->dao->query($query);
}
osc_add_hook('posted_item''wm_item_post_replace_meta_value');
« Last Edit: March 28, 2019, 11:45:03 pm by Sophia_OS »

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Replace word
« Reply #22 on: March 29, 2019, 12:28:01 am »
I'm on phone, but try Params::getParam('meta')[24]

Regards.

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Replace word
« Reply #23 on: March 29, 2019, 02:53:21 am »
I'm on phone, but try Params::getParam('meta')[24]

Regards.

Thank you very much Patrick!