Optimize multiple choice lookup

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
mghielmi
Posts: 10
Joined: 2019-01-08 01:27

Optimize multiple choice lookup

Post by mghielmi » 2019-10-19 16:26

Hi!

Reference: https://bigprof.com/blog/appgini/a-work ... gini-apps/

I've implemented this feature in my application, I need help for optimize Update and Delete function.

For update I used this code:

Code: Select all

function Tag_before_update(&$data, $memberInfo, &$args) {
	//Check for duplicate name
	$nomenew = $data['Nome'];
	$check = sql("select * from Tag where Nome='$nomenew'", $eo);

	if ($check->num_rows == 0) {
		//Retrieve current name for REPLACE query
        	$selectedID = makeSafe($data['selectedID']);        
        	$result = sql("select * from Tag where id='{$selectedID}'", $eo);
        
                if ($result->num_rows > 0) {
                	while ($row = $result->fetch_assoc()) {
                              $nomeold = $row['Nome'];    
                	}
       		}

		sql("UPDATE Clients SET Tag = REPLACE(Corsi, '$nomeold', '$nomenew')", $eo);
	}
}
Now this code work good but I need help for delete old tags.
Also if you think isn't a good solution I'm here for improve it :)

Database row Tag can contain array -> Tag1, Tag2, Tag3 ecc...

How I can manage for delete the correct Tag and also keep a correct array?
I think I need to REPLACE for ex. "Tag1" and also "Tag1, " (with space).

Do you have better idea?

Thanks for help!

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1167
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Optimize multiple choice lookup

Post by onoehring » 2019-10-23 14:20

Hi

just a quick and dirty suggestion.
You could replace "Tag1" with "," and then in a second run replace ",," with ",".
Using str_replace should not care about any space after the ,

Olaf

mghielmi
Posts: 10
Joined: 2019-01-08 01:27

Re: Optimize multiple choice lookup

Post by mghielmi » 2019-10-23 18:40

onoehring wrote:
2019-10-23 14:20
Hi

just a quick and dirty suggestion.
You could replace "Tag1" with "," and then in a second run replace ",," with ",".
Using str_replace should not care about any space after the ,

Olaf
Great idea!

I'm try!

Post Reply