Page 1 of 1

Optimize multiple choice lookup

Posted: 2019-10-19 16:26
by mghielmi
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!

Re: Optimize multiple choice lookup

Posted: 2019-10-23 14:20
by onoehring
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

Re: Optimize multiple choice lookup

Posted: 2019-10-23 18:40
by mghielmi
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!