Log in

I forgot my password

Alumni of BSU INFORMATION TECHNOLOGY

BSU INFO-TECH

FB COMMENT

add rows to table dynamically and save 2 d database

View previous topic View next topic Go down

add rows to table dynamically and save 2 d database

Post by mye on Mon 06 Dec 2010, 7:03 am


mye
Staff Sergeant
Staff Sergeant

Female
Number of posts : 113
Age : 30
Location : La Trinidad
Job/hobbies : Computer Instructor
Reputation : 0
Registration date : 2008-11-27

View user profile

Back to top Go down

Re: add rows to table dynamically and save 2 d database

Post by mye on Mon 06 Dec 2010, 7:06 am


mye
Staff Sergeant
Staff Sergeant

Female
Number of posts : 113
Age : 30
Location : La Trinidad
Job/hobbies : Computer Instructor
Reputation : 0
Registration date : 2008-11-27

View user profile

Back to top Go down

Re: add rows to table dynamically and save 2 d database

Post by mye on Mon 06 Dec 2010, 7:20 am

hi guys..i just ned help po sana d2. n d above images u can see dat initially d table has only one row.now f d user wants 2 add more rows, he/she will just click d add row button then madadagdagan ng isang vacant rows ung rows. mapapansin nu din na sa column6 my 3 checkboxes w/ 3 options wherein d user can select 1 or more from d options given.ang problema q po d2 pg clinik ng user ung submit button suposedly ang laman ng database eh eto:
Record1:
name: Max Gonzales
age: 22
gender:Male
position_applied:Accountant I
qualified:ffi
not_qualified:LE,LS

Record2:
name: Lanie Guiterez
age: 25
gender: Female
position_applied: Clerk I
qualified:ffi
not_qualified:EA

pero ang nangyayari ang laman ng field na not_qualified both in record1 and 2 eh LE,LS,EA..
kinuha nya lahat ng chineck ng user sa checkbox taz un ang isa2ve nya sa lahat ng records under not_qualified..any help po please..tnx

mye
Staff Sergeant
Staff Sergeant

Female
Number of posts : 113
Age : 30
Location : La Trinidad
Job/hobbies : Computer Instructor
Reputation : 0
Registration date : 2008-11-27

View user profile

Back to top Go down

Re: add rows to table dynamically and save 2 d database

Post by mye on Mon 06 Dec 2010, 7:25 am

ngek sri d nya pala nacontain lahat nung image kaya ung pang 6th na column na cnasabi q eh eto..



mye
Staff Sergeant
Staff Sergeant

Female
Number of posts : 113
Age : 30
Location : La Trinidad
Job/hobbies : Computer Instructor
Reputation : 0
Registration date : 2008-11-27

View user profile

Back to top Go down

Re: add rows to table dynamically and save 2 d database

Post by Lyt_Grey on Tue 07 Dec 2010, 1:44 am

Layout mo po ng DB?

yong not qualified ba iisang field lang xa??? or one field per LA, LE and LS???

kasi pwede ganito

assuming that checkboxes names are LA, LE and LS

$not_Qualified = "";

if (LA.value == true)
$not_Qualified += "LA";
if (LE.value == true)
$not_Qualified += " LE";
if (LS.value == true)
$not_Qualified += " LS;

// tas

$query = "INSERT INTO tbl_churva(.....,not_qualified) values (......," + $not_Qualified + ");";

// yan na query string... assuming yan na ang column name sa table mo for not qualified is "not_qualified".
// ung mga ...., yan ung mga ibang field na sinisave mo......

avatar
Lyt_Grey
Admin
Admin

Male
Number of posts : 308
Age : 30
Location : La Trinidad, Benguet
Job/hobbies : Ado ngem basit lang
Reputation : 0
Registration date : 2008-12-04

View user profile

Back to top Go down

Re: add rows to table dynamically and save 2 d database

Post by mye on Tue 07 Dec 2010, 1:51 am

tnx..tnx..ung not_qualified i2sang field lng xa..so bale ung value ng checkboxes na pi2liin ng user isa2ve nya sa not_qualified na field..bale pg 3 ung chineck ng user sa 1st row na input nya ang laman ng not_qualified=LA,LE,LS..pg sa second row nman eh LE lng ang chineck ng user ang laman ng not_qualified=LE..
pg i2sang row lng ang finil-apan ng user ng data ok lng ung pgsa2ve nya..kaso pg pinili na ng user ung add row taz ng-input ulit xa ng data ang laman ng field na not_qualified=lahat ng chineck ng user sa row1 and row2..dun ako ngkaproblema..

mye
Staff Sergeant
Staff Sergeant

Female
Number of posts : 113
Age : 30
Location : La Trinidad
Job/hobbies : Computer Instructor
Reputation : 0
Registration date : 2008-11-27

View user profile

Back to top Go down

Re: add rows to table dynamically and save 2 d database

Post by mye on Tue 07 Dec 2010, 1:56 am

ds s my code pala:
if(isset($_GET['button'])){

foreach($_GET['name']as $key=>$val){
if(trim($val)!='')
$name_arr[]=$val;
}
foreach($_GET['age']as $key=>$val){
if(trim($val)!='')
$age_arr[]=$val;
}
foreach($_GET['sex']as $key=>$val){
if(trim($val)!='')
$sex_arr[]=$val;
}
foreach($_GET['position']as $key=>$val){
if(trim($val)!='')
$position_arr[]=$val;
}
foreach($_GET['ffi']as $key=>$val){
if(trim($val)!='')
$ffi_arr[]=$val;
}

foreach($_GET['notQualified'] as &$value) {
$value_arr[]=$value;
}
$notQualified=implode(",", $_GET['notQualified']);


$total_records=count($name_arr);

for($i=0;$i<$total_records;$i++){
$company_name=$_GET['company_name'];
$contact_no=$_GET['contact_no'];
$contact_person=$_GET['contact_person'];
$company_type=$_GET['company_type'];
$name=$name_arr[$i];
$age=$age_arr[$i];
$sex=$sex_arr[$i];
$position=$position_arr[$i];
$ffi=$ffi_arr[$i];
//$notQualified=$notQualified_arr[i];

$query = "INSERT INTO `test`.`add` VALUES('','$company_name','$contact_no','$contact_person','$company_type','$name','$age','$sex','$position','$ffi','$notQualified')";

mye
Staff Sergeant
Staff Sergeant

Female
Number of posts : 113
Age : 30
Location : La Trinidad
Job/hobbies : Computer Instructor
Reputation : 0
Registration date : 2008-11-27

View user profile

Back to top Go down

Re: add rows to table dynamically and save 2 d database

Post by Lyt_Grey on Tue 07 Dec 2010, 2:15 am

If you use $_GET(), ano ung kinukuha? di ba ung name ng object not wether checked or uncheck xa.
avatar
Lyt_Grey
Admin
Admin

Male
Number of posts : 308
Age : 30
Location : La Trinidad, Benguet
Job/hobbies : Ado ngem basit lang
Reputation : 0
Registration date : 2008-12-04

View user profile

Back to top Go down

Re: add rows to table dynamically and save 2 d database

Post by mye on Tue 07 Dec 2010, 2:22 am

yup knukuha nya ung name ng object taz ung value isa2ve nya sa array..d2 ako sa part ng checkbox nalilito kc..ang output kc ng gnagwa q ngaun pg i2sang row lng ang ia2d ng user ok nman xa..tama ung naisa2ve na laman ng checkbox..kaso pg more than 1 row na ang ia2d ng user dun na ngkakamali ung naisa2ve na laman ng checkbox..bale ang gngwa nya kung ano ung chineck ng user sa row1 at sa lahat ng rows..un ang kinukuha nya taz un ang isa2ve sa lahat ng row..

mye
Staff Sergeant
Staff Sergeant

Female
Number of posts : 113
Age : 30
Location : La Trinidad
Job/hobbies : Computer Instructor
Reputation : 0
Registration date : 2008-11-27

View user profile

Back to top Go down

Re: add rows to table dynamically and save 2 d database

Post by mye on Tue 07 Dec 2010, 2:40 am

let's say d user input values sa row1 taz under sa not qualified column chineck nya ung EA at LS na checkbox..taz clinick nya ung add row na button so lumabas ung row2 taz finil-apan nya ulit ung taz under not qualified column chineck nya ung EA lng na checkbox..after that clinick na nya ung submit button..
sa database sa record1 not_qualified=EA,LS
record2 not_qualified=EA
un sana laman ng not_qualified na field kaso ang lumalabas ganito
sa record1 not_qualified=EA,LS,EA
record2 not_qualified=EA,LS,EA

pero pg tig-i2sa lng nman ang ini a2d ng user na record ok pa nman ung implode..tama nman ung naisa2ve sa database..haaay..i hope i made it clear Very Happy

mye
Staff Sergeant
Staff Sergeant

Female
Number of posts : 113
Age : 30
Location : La Trinidad
Job/hobbies : Computer Instructor
Reputation : 0
Registration date : 2008-11-27

View user profile

Back to top Go down

Re: add rows to table dynamically and save 2 d database

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum