girish_327
Posts: 108
|
| Posted: 04/10/2010, 10:42 PM |
|
Hello All,
I managed to store Multichebox List in Single MySQL DB Its works perfectly All Well Below is Function I use to store my Multicheckbox List for Other Users.
function ProjectCheckboxModify($Actions){
global $DBaditya_properties;
if($Actions == "Update")
{
$checkboxlist = '*'.implode('*',$_REQUEST['AmenitiesList']).'*';
for($c = 0; $c < sizeof($checkboxlist); $c++)
{
$query = "UPDATE properties SET amenities = '".$checkboxlist ."' WHERE property_id=".CCGetFromGet("property_id");
//$DBaditya_properties->query($query);
$result = mysql_query($query) or die(mysql_error());
}
}else if($Actions == "Insert")
{
$checkboxlist = '*'.implode('*',$_REQUEST['AmenitiesList']).'*';
for($c = 0; $c < sizeof($checkboxlist); $c++)
{
$query = "UPDATE properties SET amenities = '".$checkboxlist ."' WHERE property_id=".mysql_insert_id();
//$DBaditya_properties->query($query);
$result = mysql_query($query) or die(mysql_error());
}
}
}
Now I Store Values in this Format
*Parking*Furnished*Piped Gas Line*Landscape Garden*
I would like to search into Grid Using Multichebox List too.
Please HELP Me Out How to DO IT.
I am tried to Use Where Clause Using IN but its Shows Result Only if there is Single Value.
Thanks
Girish
_________________
Girish Baraskar
Web Designer/Developer
http://www.agnisdesigners.com
http://www.eindianpaintings.com
http://www.realestatekolhapur.com |
 |
 |
mamboBROWN
Posts: 1713
|
| Posted: 05/16/2010, 11:38 AM |
|
girish_327
Have you been able to resolve this??
|
 |
 |
girish_327
Posts: 108
|
| Posted: 05/16/2010, 9:17 PM |
|
No Still I cant Search Using Multicheckbox other than this everything works perfectly fine.
Girish
_________________
Girish Baraskar
Web Designer/Developer
http://www.agnisdesigners.com
http://www.eindianpaintings.com
http://www.realestatekolhapur.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 05/16/2010, 9:48 PM |
|
Hi
Is you multi check box work ok??
You just need to match based on several checked items in you lookup?
Let me know if that is what you need as I do have code that will do that for you.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
girish_327
Posts: 108
|
| Posted: 05/16/2010, 9:53 PM |
|
Yes My Insert Update Code Works Perfectly Fine just needs the help about the search
Thank you & Regards
_________________
Girish Baraskar
Web Designer/Developer
http://www.agnisdesigners.com
http://www.eindianpaintings.com
http://www.realestatekolhapur.com |
 |
 |
magus
Posts: 98
|
| Posted: 05/17/2010, 10:11 AM |
|
Greetings,
I don't think that searching your concatenated values is ever going to be easy. That is why I always use xref tables.
My current method is to insert generic function code at the end of common.php then call these functions in each page that needs to process multiple listBoxes, checkboxes etc.from the indicated events. Once you have created the events you can add other multiple select elements simply by extending the configuration array.
The typical table structure is
Main_Table.ID -> XREF_Table.MainTableID | XREF_Table.LookupID -> Lookup_Table.LookupID | Lookup_Value.
Once you have your multiples values stored in an xref table searching in accomplished easily within the CCS query builder using left joins.
I think all the necessary instructions are in the code. I hope the code isn't mangled by posting into the forum.
Also, I am not promising any support with this code. It comes from a working project so it works. The implementation is over to whoever might want to use it.
Regards,
Don A
PS. The forum reports this post is too big so I will split it across several.
|
 |
 |
magus
Posts: 98
|
| Posted: 05/17/2010, 10:12 AM |
|
/*
##### Multiple Xref Value Field Handling Functions
For USE in a page you must set up the configuration arrays with the format below in the Page After_Initialize Event
THEN call the functions from page events as follows:
function multi_set_xref_values(&$db, &$lookups, & $Component, $record_key = "") Call this function in the Record Component
AfterExecuteSelect Event
function multi_prepare_xref_lookups(&$db, &$lookups, &$component = 0) is called
BeforeBuildInsert event and
BeforeBuildUpdate event
function multi_insert_xref_lookups(&$db, &$lookups, $record_key) is called
AfterExecuteInsert event
function multi_update_xref_lookups(&$db, &$lookups) is called
AfterExecuteUpdate event
function multi_delete_xref-lookups($db, $lookups) is called
AfterExecuteDelete event
// Then use generic code to process the arrays.
// the structure of the array
// called $lookups // Array name can be customised just make sure correct array is passed to functions.
// SET UP ARRAYS for each multiselect component
// Recommended to use a different configuration array for each form component
// global $lookups;
// $lookups = array();
// $name = 'component_grp_name';
// $lookups[$name] = array();
// $lookups[$name]['cnames'] = array();
###
### // $lookups[$name]['form_component_name'] = '';
### NOT USED Could be useful to know container name.
// $lookups[$name]['form_component_key'] = ''; What is the form component primary key parameter name? e.g. id
// Remember that this has to be called from mysql insert id on after insert.
// $record_key = mysql_insert_id($Component->ds->Link_ID);
// $lookups[$name]['cnames'][] = 'component_name'; } OPTIONALLY
// $lookups[$name]['cnames'][] = 'component_name'; } Can Concatenate Values From Multiple Components
// $lookups[$name]['cnames'][] = 'component_name'; }
// $lookups[$name]['xref_table_name'] = '';
// $lookups[$name]['parent_key_field_name'] = ''; // This is the field in the xref table where the form record key is stored
// $lookups[$name]['xref_value_field_name'] ='';
## // $lookups[$name]['parent_text_component_name'] // This is only useful if you are populating a separate parent component DB value with concatenated text values
## // $lookups[$name]['text_values_lookup_query'] ='SELECT ...';
## If you want updates to leave existing still wanted entires rather than delete everything and insert new records, then create this parameter key.
// $lookups[$name]['true_update'] = 1;
*/
function multi_set_xref_values(&$db, &$lookups, & $Component, $recordkey = "") {
// This function is called to create a global array of all Component lookup values.
// $lookups must be an array
if(!is_array($lookups)) return false;
reset($lookups);
foreach ($lookups as $key => $comp_grp) {
$record_key = strlen($recordkey) ? $recordkey: CCGetParam($comp_grp['form_component_key']);
if (is_numeric($record_key)) {
$sql = "SELECT ". $comp_grp['xref_value_field_name']
." FROM ". $comp_grp['xref_table_name']
." WHERE ". $comp_grp['parent_key_field_name'] ." = ". $record_key
." GROUP BY ". $comp_grp['xref_value_field_name'];
$selected_values = getSelectedList(&$db,$sql);
foreach ($comp_grp['cnames'] as $key => $component_name) {
$Component->$component_name->SetValue($selected_values);
}
} else {
$Component->Value = "";
}
}
}
function multi_prep_xref_values_array(&$cnames) {
// This function is called by multi_prepare_xref_lookups
// It receives the 'cname' branch of the lookups array
// and finds the value for each parameter
// and saves these in an array and as a comma delimited string.
// It returns an array that includes both.
// $cname must be an array
if(!is_array($cnames)) return false;
$returned_values['values'] = array();
$value_str = "";
foreach ($cnames as $key => $component_name) {
$value = $_POST[$component_name];
if(is_array($value)) {
if(count($value)) {
foreach($value as $i=>$v) {
$returned_values['values'][] = intval($v);
$value_str = $value_str . intval($value) .",";
}
}
} else if (strlen($value)) {
$returned_values['values'][] = intval($value);
$value_str = intval($value);
}
}
$returned_values['str_value'] = (isset($value_str))? substr($value_str, 0, -1): "";
return $returned_values;
}
function multi_prepare_xref_lookups(&$db, &$lookups, &$component = 0) {
// This function is called in the before_ insert or update events
// It takes a database connection to use and the array
// containing the $lookup configuration data.
// $lookups must be an array
if(!is_array($lookups)) return false;
reset($lookups);
// First step is to get the parameter values and add them to the $lookups array
foreach ($lookups as $key => $comp_grp) {
$lookup_values = multi_prep_xref_values_array($comp_grp['cnames']);
if($lookup_values === false) exit('multi_prepare_xref_lookups function error');
if(array_key_exists('values', $lookup_values)) {
$lookups[$key]['values'] = $lookup_values['values'];
} else {
$lookups[$key]['values'] = null;
}
if(array_key_exists('str_value', $lookup_values)) {
$lookups[$key]['str_value'] = $lookup_values['str_value'];
} else {
$lookups[$key]['str_value'] = null;
}
}
}
function multi_insert_xref_lookup(&$db, &$comp_grp, $record_key) {
// Array ref
// array_name[$name]['cnames'][] = 'component_name';
// array_name[$name]['xref_table_name'] = '';
// array_name[$name]['parent_key_field_name'] = '';
// array_name[$name]['xref_value_field_name'] ='';
if(array_key_exists('values', $comp_grp)) {
for($i = 0; $i < sizeof($comp_grp['values']); $i++) {
$sql = "INSERT INTO ". $comp_grp['xref_table_name'] ."( "
. $comp_grp['parent_key_field_name'] .", "
. $comp_grp['xref_value_field_name']
. " ) VALUES ('"
. $record_key . "', '"
. $comp_grp['values'][$i]
. "')";
$db->query($sql);
}
} else {
return false;
}
return true;
}
function multi_insert_xref_lookups(&$db, &$lookups, $recordkey) {
// This function is called in the insert and update events
// It takes a database connection to use and the array
// containing the lookup configuration data.
// It passes these through to multi_insert_xref_lookup()
// $lookups must be an array
if(!is_array($lookups)) return false;
reset($lookups);
foreach ($lookups as $key => $component_grp) {
$record_key = strlen($recordkey) ? $recordkey : CCGetParam($component_grp['form_component_key']);
if (is_numeric($record_key)) {
multi_insert_xref_lookup(&$db, $component_grp, $record_key);
}
}
}
|
 |
 |
magus
Posts: 98
|
| Posted: 05/17/2010, 10:12 AM |
|
function multi_update_xref_lookup(&$db, &$comp_grp, $record_key) {
// Array ref
// array_name[$name]['cnames'][] = 'component_name';
// array_name[$name]['xref_table_name'] = '';
// array_name[$name]['parent_key_field_name'] = '';
// array_name[$name]['xref_value_field_name'] ='';
// NOTE this function does not touch existing records that are still wanted.
// Find the pre-existing entries
$sql = "SELECT ". $comp_grp['xref_value_field_name'] ." FROM ". $comp_grp['xref_table_name']
." WHERE ". $comp_grp['parent_key_field_name'] ." = ". CCToSQL( $record, ccsInteger) ;
$pre_existing = GetSelectedList($ $db, $sql);
// If no pre-existing entries then just insert new ones
if(!COUNT($pre_existing) ) {
multi_insert_xref_lookup(&$db, $comp_grp, $record_key);
return;
}
// Now test current values. If nothing being requested, then just delete
if(!COUNT($comp_grp['values']) ) {
multi_delete_xref_lookup(&$db, $comp_grp, $record_key);
return;
}
// if existing not among current then delete
$delete_these = array_diff($pre_existing, $comp_grp['values']);
if(COUNT($delete_these) ) {
for($i = 0; $i < sizeof($delete_these); $i++) {
$sql = "DELETE FROM ". $comp_grp['xref_table_name']
." WHERE ". $comp_grp['parent_key_field_name'] ." = ". CCToSQL($record_key, ccsInteger)
." AND ". $comp_grp['xref_value_field_name'] ." = ". CCToSQL($insert_these[$i], ccsInteger) ." LIMIT 1" ;
$db->query($sql);
}
}
// if current not among existing then insert.
$insert_these = array_diff($comp_grp['values'], $pre_existing);
if(COUNT($insert_these)) {
for($i = 0; $i < sizeof($insert_these); $i++) {
$sql = "INSERT INTO ". $comp_grp['xref_table_name'] ."( "
. $comp_grp['parent_key_field_name'] .", "
. $comp_grp['xref_value_field_name']
. " ) VALUES ("
. CCToSQL($record_key, ccsInteger) . ", "
. CCToSQL($insert_these[$i], ccsInteger)
. ") LIMIT 1";
$db->query($sql);
}
}
}
function multi_update_xref_lookups(&$db, &$lookups) {
// This function is called in the insert and update events
// It takes a database connection to use and the array
// containing the lookup configuration data.
// It passes these through to insert_xref_lookup()
// $lookups must be an array
if(!is_array($lookups)) return false;
reset($lookups);
foreach ($lookups as $key => $component_grp) {
$record_key = CCGetParam($component_grp['form_component_key']);
// Sometime we need an update operation where the xref table contains other data. e.g. sequencing
if (is_numeric(record_key) && isset($component_grp['true_update']) ) {
multi_update_xref_lookup(&$db, $component_grp, $record_key);
} else if (is_numeric($record_key)) {
// An (insert delete) update is good for keeping xref tables clean.
multi_delete_xref_lookup(&$db, $component_grp, $record_key);
multi_insert_xref_lookup(&$db, $component_grp, $record_key);
}
}
}
function multi_delete_xref_lookup(&$db, &$comp_grp, $record_key) {
if(!strlen($record_key) || !is_numeric($record_key)) return false;
$sql = "DELETE FROM ". $comp_grp['xref_table_name'] ." WHERE ". $comp_grp['parent_key_field_name'] ." = ".$record_key;
$db->query($sql);
}
function multi_delete_xref_lookups(&$db, &$lookups) {
// This function is called in the insert and update events
// It takes a database connection to use and the array
// containing the lookup configuration data.
// $lookups must be an array
if(!is_array($lookups)) return false;
reset($lookups);
foreach ($lookups as $key => $component_grp) {
$record_key = CCGetParam($component_grp['form_component_key']);
if (is_numeric($record_key)) {
multi_delete_xref_lookup(&$db, $component_grp, $record_key);
}
}
}
?>
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 05/18/2010, 7:03 AM |
|
Hi
Building a search for this depends on how you are planning to pass the search criteria to your form.
Tha example below is assuming you have a seach form in CCS built that sends the multi check box data as part of your seach criteria. If not, there should be enough info here where you could modify it for your needs.
First step is in the Before Build Select event for your grid form create a Custom Code Action like below...
if(CCGetParam("s_MutiCheckBoxControl,"")){ // Check to see if the multi check box was sent as part of the search
$SearchValue=CCGetParam("s_MutiCheckBoxControl,"");
$DBField = "FieldInDBtoSearch"; // Your tables field name that has your multi checkbox data in it.
$Delim = "*"; //The delimiter your are using to store multi checks in your DB (I usually use ~~ as the DB delimiter so most any char can be in the CB Text).
$Connector=" AND "; //Use if occurrence of all checked items are to be found eg: exact match
//$Connector=" OR "; //Use if any checked item causes a match
$TSQL=$Component->ds->Where; //Get the existing Where Clause
if($TSQL){ $TSQL .= " AND ";} // The Connector if a Where clause already exists
$TSQL .="(";
$ArrayNum=count($SearchValue);
$i=1;
while($i<$ArrayNum){
$TQSL .=' INSTR("'.$Delim.$SearchValue[$i-1].$Delim.'" , '.$DBField.') > 0 '.$Connector;
$i++;
}
$TQSL .=' INSTR("'.$Delim.$SearchValue[$i-1].$Delim.'" , '.$DBField.') > 0 ';
$TSQL .=")";
$Component->ds->Where=$TSQL;
//echo "NEW SQL WHERE STMT: ".$TSQL." --END SQL ".$test; die(); //Remove after $TSQL looks Valid
}
This also works for Multi Item List boxes as well
If you need to just comment out the echo statement and you can check the SQL generated for debugging.
Let me know if this helps.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
girish_327
Posts: 108
|
| Posted: 05/18/2010, 7:13 AM |
|
Thanks a lot for all your reply. I will try these codes and let you know the result.
Thanks again
_________________
Girish Baraskar
Web Designer/Developer
http://www.agnisdesigners.com
http://www.eindianpaintings.com
http://www.realestatekolhapur.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 05/18/2010, 7:19 AM |
|
BTW:
I usually do the generation of the field for storing the multi checkbox or multi listbox code in the on Validate event, custom code.
No real reason except that way I only have the code in there once instead of the update and insert events.
EG:
$Temp = CCGetParam("MultiControlName","");
//echo $Temp." ".$Temp[0]." ".$$Temp[1];
$Delim="~~";
if($Temp[0]==""){$Component->Errors->addError("Required Value Error Text");return true;} // This Code if it is a required field.
if($Temp)
{
$DBValue = implode($Delim,$Temp);
$DBValue=$Delim.$DBValue.$Delim;
$Container->MultiControlName->SetValue($DBValue);
}
It's a good idea to make the DB Field of YourTargetControl to be a TEXT Type field. That way it will not make a diff what length of data is in your bound columns for the multi control.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 05/18/2010, 7:21 AM |
|
Hope these ideas help.
Let me know
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 05/18/2010, 7:49 AM |
|
BTW..
Did you develop code to repopultate the check box list on record display from the Database to show the multi selections??
If not.. Let me know, I can show you code to do that also.
Have fun
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 05/18/2010, 8:15 AM |
|
You might need to change the CCGetFromGets to CCGetParam..
if(CCGetParam("s_MutiCheckBoxControl,"")){ // Check to see if the multi check box was sent as part of the search
$SearchValue=CCGetParam("s_MutiCheckBoxControl,"");
In the above code for search
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 05/20/2010, 9:23 AM |
|
Hi Girish
Just wondering if you got this to work????
I am curious.
BTW. If you want to be able to select exact match or any match from your Search Form you could add a check box to the search form "Exact Match" and set the checked value to 1.
Then just change the code in the example I sent above to look like this:
$Connector=" OR "; //Use if any checked item causes a match
if(CCGetParam("ExactMatchControlName","")==1) $Connector=" AND "; //Use if occurrence of all checked items are to be found eg: exact match
I am guessing it is for your real estate site. This would give your visitors a choice in their property searches.
Let me know how it goes.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
girish_327
Posts: 108
|
| Posted: 05/21/2010, 6:25 AM |
|
Hello John Real,
I am very sorry I am right very busy with a few projects but I will definitely try this in next two days and I will get back to you.
THANKS A LOT FOR YOUR SUPPORT.
_________________
Girish Baraskar
Web Designer/Developer
http://www.agnisdesigners.com
http://www.eindianpaintings.com
http://www.realestatekolhapur.com |
 |
 |
|