Get KoolPHP UI with 30% OFF!

select-update-insert

Igor
Hi,
i have select query that retrieve 7 columns from table analitika and 2 columns from table klijent
	
$ds->SelectCommand = 'select 
			analitika.klijent, 
			analitika.distr, 
			analitika.struja, 
			analitika.strDtmDo, 
			analitika.kategorijaStruja, 
			analitika.plnDtmDo, 
			analitika.kategorijaPlin, 
			analitika.strucna_napomena,
			klijent.aktivnost,
			klijent.opis_aktivnosti
			from analitika, klijent
			WHERE 
			analitika.klijent = klijent.klijent';

i can¸t figure it out how to update, insert and delete:
  1. I dont want to have fields aktivnost, opis_aktivnosti from table klijent in insert form
  2. i want to update only fields in table analitika (fields aktivnost and opis_aktivnosti can be read only)
  3. i want to delete only fields in table aktivnost

Is that even possible? :)
Igor
Posted Jan 18, 2017 , edited Jan 18, 2017 Kool
David
Hi Igor,
For update, insert and delete you need to set $ds->UpdateCommand, $ds->InsertCommand and $ds->DeleteCommand.
1. If you don't want some fields in insert form you could set their columns' ReadOnly = true:
http://doc.koolphp.net/Controls/KoolGrid/PHP/GridColumn/index.php#ReadOnly
Unfortunately, this will only make them not updatable.
2. If your UpdateCommand in sql only set update for one of your table, the other table won't be update.
3. Similarly you could set your DeleteCommand for only one of your table.
Please let us know if you need further details. Thanks!
Posted Jan 19, 2017 Kool
Igor
Hi David,
1. OK
2. i did, still not working
	
$ds->UpdateCommand = 'update analitika
			set 
			id="@id", 
			klijent="@klijent", 
			distr="@distr", 
			struja="@struja", 
			strDtmDo="@strDtmDo", 
			kategorijaStruja="@kategorijaStruja", 
			plnDtmDo="@plnDtmDo", 
			kategorijaPlin="@kategorijaPlin", 
			strucna_napomena="@strucna_napomena", 
			username="@username"
			WHERE
			id="@id"
			username= "'.$_SESSION['login_user'].'"';

3. not working
$ds->DeleteCommand = 'delete from analitika where id="@id"'; 

4. insert is OK
	
$ds->InsertCommand = 'INSERT INTO analitika(id, klijent, distr, struja, strDtmDo, kategorijaStruja, plnDtmDo, kategorijaPlin, strucna_napomena, username) values ("@id", "@klijent", "@distr", "@struja", "@strDtmDo", "@kategorijaStruja", "@plnDtmDo", "@kategorijaPlin", "@strucna_napomena", "'.$_SESSION['login_user'].'")';

tnx for help :)
Posted Jan 19, 2017 , edited Jan 19, 2017 Kool
David
Hi Igor,
Please add the id field in the select command query so the grid knows which id to pass for each row when it updates or delete the data. Please try this and let us know if this works or there's any problem left. Thanks!
Posted Jan 20, 2017 Kool
Igor
Hi,
select, insert, delete are working now, but when i try to update something wierd is happening, after insert i can update that inserted row but only ones, hm..
$ds->UpdateCommand = 'update analitika
			set 
			id="@id", 
			klijent="@klijent", 
			distr="@distr", 
			struja="@struja", 
			strDtmDo="@strDtmDo", 
			kategorijaStruja="@kategorijaStruja", 
			plnDtmDo="@plnDtmDo", 
			kategorijaPlin="@kategorijaPlin", 
			strucna_napomena="@strucna_napomena", 
			username="@username"
			WHERE
			id="@id"
			AND
			username= "'.$_SESSION['login_user'].'"';

Igor
Posted Jan 20, 2017 , edited Jan 20, 2017 Kool