Jump to content

shaddf

Members
  • Posts

    102
  • Joined

  • Last visited

Everything posted by shaddf

  1. is it possible to insert data from such a select like so: loop1: WHILE i<in_Dept_TOT DO INSERT INTO _epttbl(Project_id,Dept_id) VALUES(Result,SELECT SPLIT_STRING(in_Deptid, '||',i)); SET i=i+1; END WHILE loop1; Or is it better likeso: loop1: WHILE i<in_Dept_TOT DO SELECT SPLIT_STRING(in_Deptid, '||',i) into myvar ; INSERT INTO _epttbl(Project_id,Dept_id) VALUES(Result,myvar); SET i=i+1; END WHILE loop1;
  2. No ido not mean cache.what I want is to pass a php array variable to a mysql stored procedure from php
  3. Thanks for the double pipe idea.how can i split the string back and assign it to a cursor in the stored procedure.
  4. Sorry but ,i may have an array containing a sentences like "this is your day.Go for it","You are doing it well","Keep it up!".how caan I pass that array to a stored procedure.so that I can assign it to a cursor in the procedure
  5. i have this array: test={'dog','cow','shee'}; how can I pass it to a stored procedure: call sp_array(in i_arr1 text); what data type should I use? Iam currently looping through and multi executing the procedure in php to pass the values one by one .But is there a way to pass it to the procedure and then assign it to a cursor in sql.
  6. I have this table: CREATE TABLE _HRatortbl ( Hor_id INT unsigned NOT NULL auto_increment, Hicator_title longtext NOT NULL, Primary KEY(HRindicator_id), UNIQUE KEY ix_length_HRindicator_title (HRindicator_title(255)) )ENGINE=InnoDB DEFAULT CHARSET=utf8 why is it that it cannot differentiate between: Legally stipulated Age for marriage and legally stipulated age for mariage I found them both iniside the table .Is there another way to do this on text fields
  7. what data type can I use to define a text field input parameter in the stored procedure below;in the data base table it is defined as: comment text, and in the stored procedure how can I define it: CREATE PROCEDURE sp_ne comm(in in_Nature_id varchar(256)/text) MODIFIES SQL DATA BEGIN insert into me(comment)values(in_Nature_id ie vvvv uygliuyiuyo......>256 characters); END
  8. It is a mysql question .how can Iselect data while replacing all returned columns with "All_other as null"
  9. I have this query : select GROUP_CONCAT(Other_type)as projtype2,PrT_id from _Otherproject_typetbl,_project_typetbl where _Otherproject_typetbl.Other_id=_project_typetbl.Other_id and Project_id=in_projid; and it gives this result: +-----------+--------+ | projtype2 | PrT_id | +-----------+--------+ | All_other | HR_3 | +-----------+--------+ 1 row in set (0.04 sec) I would to set the value incase it is "Allother" to be set to empty or null in any of the columns +-----------+--------+ | projtype2 | PrT_id | +-----------+--------+ | null | HR_3 | +-----------+--------+ 1 row in set (0.04 sec)
  10. DROP PROCEDURE IF EXISTS sp_addnewstratplandetails $$ CREATE PROCEDURE sp_addnewstratplandetails(IN in_stratprio_id int,IN in_Plalt varchar(255),in in_Out varchar(255),in in_Actes varchar(255),in in_performars varchar(255),in in_tar varchar(255),in in_state int) MODIFIES SQL DATA BEGIN DECLARE Result1 int; DECLARE pcnt1 int; DECLARE o_id varchar(255);DECLARE in_Outrids varchar(255); DECLARE in_actids varchar(255);DECLARE in_pids varchar(255); DECLARE r_id varchar(255); DECLARE in_PLANrids varchar(255); DECLARE pcnt int; DECLARE a_id varchar(255); DECLARE pcntI int; DECLARE p_id varchar(255);DECLARE in_tids varchar(255); DECLARE pcntt int; DECLARE pchk int; DECLARE lo_id int; DECLARE l_AO_id int; DECLARE l_perfo_id int; DECLARE l_tar_id int; DECLARE t_id varchar(255); DECLARE in_Pllt_id varchar(20); DECLARE l_out_id varchar(20); DECLARE l_Actes_id varchar(20); DECLARE l_pers_id varchar(20); DECLARE l_tar_id varchar(20); DECLARE exit handler for sqlexception BEGIN /* ERROR*/ ROLLBACK; SELECT CONCAT('Error occurred – Record not saved!')as "Result"; END; DECLARE exit handler for sqlwarning BEGIN /* WARNING*/ ROLLBACK; SELECT CONCAT('Error:Record not saved already Exists! ') as "Result"; END; START TRANSACTION; /*check if plad result exists*/ SELECT count(*) into Result1 FROM _Plantstbl WHERE Plannult=in_Plalt and EXISTS (SELECT * FROM _stratbl WHERE _Plantstbl.PlannedResult_id=_stratbl.Plannult_id and stratprio_id=in_stratprio_id); IF Result1=0 && in_state=0 THEN SELECT count(*) into pcnt from _Plantstbl where Plannult_id like concat(in_stratprio_id,'%'); SET r_id=pcnt+1; SET in_PLANrids=concat(in_stratprio_id,'.',r_id); INSERT INTO _Plantstbl(Plannult_id,Plannsult) VALUES(in_PLANrids,in_Plalt); ELSE UPDATE _Plantstbl SET Plannsult=in_Plalt WHERE PlannedResult=in_Plalt; END IF; SELECT Plannult_id into in_Pllt_id FROM _Plantstbl WHERE Plannsult=in_Plalt ; SELECT count(*) into lo_id FROM Out_tbl WHERE outcome=in_Out ; IF lo_id=0 THEN SELECT count(*) into pcnt1 from Out_tbl where out_id like concat(in_Pllt_id,'.','%'); SET o_id=pcnt1+1; SET in_Outrids=concat(in_Pllt_id,'.',o_id); INSERT INTO Out_tbl(out_id,outme) VALUES(in_Outrids,in_Out); ELSE UPDATE Out_tbl SET outcome=in_Out WHERE outcome=in_Out ; END IF; SELECT count(*) into l_AO_id FROM _Plastbl WHERE Actes=in_Actes; IF l_AO_id=0 THEN SELECT out_id into l_out_id FROM Out_tbl WHERE outcome=in_Out ; SELECT count(*) into pcnt from _Plastbl where Actes_id like concat(l_out_id,'.','%'); SET a_id=pcnt+1; SET in_actids=concat(l_out_id,'.',a_id); INSERT INTO _Plastbl(Actes_id,Actes) VALUES(in_actids,in_Actes); ELSE UPDATE _Plastbl SET Actes=in_Actes WHERE Actes=in_Actes ; END IF; SELECT count(*) into l_perfo_id FROM _Pertbl WHERE perfors=in_performars; IF l_perfo_id=0 THEN SELECT count(*) into pcntI from _Pertbl where Pind_id like concat(l_out_id,'.','%'); SET p_id=pcntI+1; SET in_pids=concat(l_out_id,'.',p_id); INSERT INTO _Pertbl(Pind_id,perfors) VALUES(in_pids,in_performars); ELSE UPDATE _Pertbl SET perfors=in_performars WHERE perfors=in_performars; END IF; SELECT count(*) into l_tar_id FROM _Ttbl WHERE tar=in_tar; IF l_tar_id=0 THEN SELECT count(*) into pcntt from _Ttbl where tar_id like concat(l_out_id,'.','%'); SET t_id=pcntt+1; SET in_tids=concat(l_out_id,'.',t_id); INSERT INTO _Ttbl(tar_id,tar) VALUES(in_tids,in_tar); ELSE UPDATE _Ttbl SET tar=in_tar WHERE tar=in_tar; END IF; COMMIT; SELECT Actes_id into l_Actes_id FROM _Plastbl WHERE Actes=in_Actes; SELECT Pind_id into l_pers_id FROM _Pertbl WHERE perfors=in_performars; SELECT tar_id into l_tar_id FROM _Ttbl WHERE tar=in_tar; INSERT INTO _stratbl(stratprio_id,Plesult_id,out_id,Actes_id,Pind_id,tar_id ) VALUES(in_stratprio_id,in_Pllt_id,l_out_id,l_Actes_id,l_pers_id ,l_tar_id); SELECT 'success '; END$$ DELIMITER ; that is the stored procedure code. and this is the php: Array ( [Japanese] => Array ( [hot] => wasabi [salty] => soy sauce [sweety] => soy rdsauce [bitter] => pepper sauce ) [Chinese] => Array ( [hot] => wasabi [salty] => soy sauce [sweety] => soy rdsauce_one [bitter] => pepper sauce3 ) [indian] => Array ( [hot] => wasabi [salty] => soy sauce [sweety] => soy rdsauce [bitter] => pepper sauce4 ) [mexican] => Array ( [hot] => soanzo [salty] => soy sauce1 [sweety] => soy sauceeur [bitter] => pepper sauce_sausage ) [russian] => Array ( [hot] => soanzo [salty] => soy sauce1 [sweety] => soy sauceeur [bitter] => pepper sauce_pork ) [ganda] => Array ( [hot] => soanzo [salty] => soy sauce1 [sweety] => soy sauce_beef [bitter] => luwombo_chicken ) ) DROP PROCEDURE IF EXISTS sp_addnewstratplandetails $$ CREATE PROCEDURE sp_addnewstratplandetails(IN in_stratprio_id int,IN in_Plalt varchar(255),in in_Out varchar(255),in in_Actes varchar(255),in in_performars varchar(255),in in_tar varchar(255),in in_state int) MODIFIES SQL DATA BEGIN DECLARE Result1 int; DECLARE pcnt1 int; DECLARE o_id varchar(255);DECLARE in_Outrids varchar(255); DECLARE in_actids varchar(255);DECLARE in_pids varchar(255); DECLARE r_id varchar(255); DECLARE in_PLANrids varchar(255); DECLARE pcnt int; DECLARE a_id varchar(255); DECLARE pcntI int; DECLARE p_id varchar(255);DECLARE in_tids varchar(255); DECLARE pcntt int; DECLARE pchk int; DECLARE lo_id int; DECLARE l_AO_id int; DECLARE l_perfo_id int; DECLARE l_tar_id int; DECLARE t_id varchar(255); DECLARE in_Pllt_id varchar(20); DECLARE l_out_id varchar(20); DECLARE l_Actes_id varchar(20); DECLARE l_pers_id varchar(20); DECLARE l_tar_id varchar(20); DECLARE exit handler for sqlexception BEGIN /* ERROR*/ ROLLBACK; SELECT CONCAT('Error occurred – Record not saved!')as "Result"; END; DECLARE exit handler for sqlwarning BEGIN /* WARNING*/ ROLLBACK; SELECT CONCAT('Error:Record not saved already Exists! ') as "Result"; END; START TRANSACTION; /*check if plad result exists*/ SELECT count(*) into Result1 FROM _Plantstbl WHERE Plannult=in_Plalt and EXISTS (SELECT * FROM _stratbl WHERE _Plantstbl.PlannedResult_id=_stratbl.Plannult_id and stratprio_id=in_stratprio_id); IF Result1=0 && in_state=0 THEN SELECT count(*) into pcnt from _Plantstbl where Plannult_id like concat(in_stratprio_id,'%'); SET r_id=pcnt+1; SET in_PLANrids=concat(in_stratprio_id,'.',r_id); INSERT INTO _Plantstbl(Plannult_id,Plannsult) VALUES(in_PLANrids,in_Plalt); ELSE UPDATE _Plantstbl SET Plannsult=in_Plalt WHERE PlannedResult=in_Plalt; END IF; SELECT Plannult_id into in_Pllt_id FROM _Plantstbl WHERE Plannsult=in_Plalt ; SELECT count(*) into lo_id FROM Out_tbl WHERE outcome=in_Out ; IF lo_id=0 THEN SELECT count(*) into pcnt1 from Out_tbl where out_id like concat(in_Pllt_id,'.','%'); SET o_id=pcnt1+1; SET in_Outrids=concat(in_Pllt_id,'.',o_id); INSERT INTO Out_tbl(out_id,outme) VALUES(in_Outrids,in_Out); ELSE UPDATE Out_tbl SET outcome=in_Out WHERE outcome=in_Out ; END IF; SELECT count(*) into l_AO_id FROM _Plastbl WHERE Actes=in_Actes; IF l_AO_id=0 THEN SELECT out_id into l_out_id FROM Out_tbl WHERE outcome=in_Out ; SELECT count(*) into pcnt from _Plastbl where Actes_id like concat(l_out_id,'.','%'); SET a_id=pcnt+1; SET in_actids=concat(l_out_id,'.',a_id); INSERT INTO _Plastbl(Actes_id,Actes) VALUES(in_actids,in_Actes); ELSE UPDATE _Plastbl SET Actes=in_Actes WHERE Actes=in_Actes ; END IF; SELECT count(*) into l_perfo_id FROM _Pertbl WHERE perfors=in_performars; IF l_perfo_id=0 THEN SELECT count(*) into pcntI from _Pertbl where Pind_id like concat(l_out_id,'.','%'); SET p_id=pcntI+1; SET in_pids=concat(l_out_id,'.',p_id); INSERT INTO _Pertbl(Pind_id,perfors) VALUES(in_pids,in_performars); ELSE UPDATE _Pertbl SET perfors=in_performars WHERE perfors=in_performars; where are thos errors you have just found
  11. it has managed to save with the code below but it is not saving the second record of the array.why is it not looping through for ($i = 0, $num_specials = count($arr); $i < $num_specials; $i++) { include("config.php"); $strat_sql="call sp_addnewetails(?,?,?,?,?,?)"; $insert_t_stmt=$mysqli->prepare($strat_sql)or die($mysqli->error); #associate variables with the input parameters $insertt_stmt->bind_param("isssss",$my_prioid,$my_planid,$my_outcome_id,$my_Activities_id,$my_performanceIndicator_id,$my_target_id); #i=integer //aggregate the records to save $my_prioid =$_POST['strat_priorities']; $my_planid=stripslashes($plan); for ($m = 0, $num_sub = count($arr[$i]); $m < $num_sub; $m++) { //save record $my_id=stripslashes($arr[$i][$m]); $my_Act_id=stripslashes($arr[$i][$m]); $my_p_id=stripslashes($arr[$i][$m]); $my_t_id=stripslashes($arr[$i][$m]); #Execute the statement $insert_t_stmt->execute( ) or die ($insert_t_stmt->error); $insert_t_stmt->bind_result($Entryerr); while ($insert_strat_stmt->fetch( )) { $error12=$Entryerr; if(substr($error12,0, 4)=="succ"){$suc=$error12;} } }//inner for $insert_t_stmt->close( ); $mysqli->close( ); }//end outer for
  12. why is it that it works for one record.that is when the for loop is out it does work well. but when i try to do it multiple times it does not do anything:it does not insert any record .And iam concrete sure that the data is there in the array as seen from the reply through ajax iuhioh[oijoi rec1 ii[oioij rec2 oijoi]op]po rec3 iuuiho[iuho[i rec4 Is it because of the transaction that has manytables to insert into data ,why?? $strat_sql="call sp_addnewetails(?,?,?,?,?,?)"; $insert_t_stmt=$mysqli->prepare($strat_sql)or die($mysqli->error); #associate variables with the input parameters $insertt_stmt->bind_param("isssss",$my_prioid,$my_planid,$my_outcome_id,$my_Activities_id,$my_performanceIndicator_id,$my_target_id); #i=integer //aggregate the records to save $my_prioid =$_POST['strat_priorities']; $my_planid=stripslashes($plan); //save record $my_id="you";//stripslashes($arr[$i][$m]); $my_Act_id="me";//stripslashes($arr[$i][$m]); $my_p_id="him";//stripslashes($arr[$i][$m]); $my_t_id="her";//stripslashes($arr[$i][$m]); #Execute the statement $insert_t_stmt->execute( ) or die ($insert_t_stmt->error); $insert_t_stmt->bind_result($Entryerr); while ($insert_strat_stmt->fetch( )) { $error12=$Entryerr; if(substr($error12,0, 4)=="succ"){$suc=$error12;} } $insert_t_stmt->close( ); $mysqli->close( );
  13. how can i use php to enter records into mysql using a transaction ; I have this stored procedure below.how can i excute itt using php to insert data from an array like this one: Array ( [Japanese] => Array ( [hot] => wasabi [salty] => soy sauce [sweety] => soy rdsauce [bitter] => pepper sauce ) [Chinese] => Array ( [hot] => wasabi [salty] => soy sauce [sweety] => soy rdsauce_one [bitter] => pepper sauce3 ) [indian] => Array ( [hot] => wasabi [salty] => soy sauce [sweety] => soy rdsauce [bitter] => pepper sauce4 ) [mexican] => Array ( [hot] => soanzo [salty] => soy sauce1 [sweety] => soy sauceeur [bitter] => pepper sauce_sausage ) [russian] => Array ( [hot] => soanzo [salty] => soy sauce1 [sweety] => soy sauceeur [bitter] => pepper sauce_pork ) [ganda] => Array ( [hot] => soanzo [salty] => soy sauce1 [sweety] => soy sauce_beef [bitter] => luwombo_chicken ) ) i have tried this so far but no good: include("config.php"); $strat_sql="call sp_addnewetails(?,?,?,?,?,?)"; $insert_t_stmt=$mysqli->prepare($strat_sql)or die($mysqli->error); #associate variables with the input parameters $insertt_stmt->bind_param("isssss",$my_prioid,$my_planid,$my_outcome_id,$my_Activities_id,$my_performanceIndicator_id,$my_target_id); #i=integer //aggregate the records to save $my_prioid =$_POST['strat_priorities']; $my_planid=stripslashes($plan); for ($i = 0, $num_specials = count($arr); $i < $num_specials; $i++) { for ($m = 0, $num_sub = count($arr[$i]); $m < $num_sub; $m++) { //save record $my_id=stripslashes($arr[$i][$m]); $my_Act_id=stripslashes($arr[$i][$m]); $my_p_id=stripslashes($arr[$i][$m]); $my_t_id=stripslashes($arr[$i][$m]); #Execute the statement $insert_t_stmt->execute( ) or die ($insert_t_stmt->error); $insert_t_stmt->bind_result($Entryerr); while ($insert_strat_stmt->fetch( )) { $error12=$Entryerr; if(substr($error12,0, 4)=="succ"){$suc=$error12;} } }//inner for } $insert_t_stmt->close( ); $mysqli->close( );
  14. i have tried this so far but no good: include("config.php"); $strat_sql="call sp_addnewetails(?,?,?,?,?,?)"; $insert_t_stmt=$mysqli->prepare($strat_sql)or die($mysqli->error); #associate variables with the input parameters $insertt_stmt->bind_param("isssss",$my_prioid,$my_planid,$my_outcome_id,$my_Activities_id,$my_performanceIndicator_id,$my_target_id); #i=integer //aggregate the records to save $my_prioid =$_POST['strat_priorities']; $my_planid=stripslashes($plan); for ($i = 0, $num_specials = count($arr); $i < $num_specials; $i++) { for ($m = 0, $num_sub = count($arr[$i]); $m < $num_sub; $m++) { //save record $my_id=stripslashes($arr[$i][$m]); $my_Act_id=stripslashes($arr[$i][$m]); $my_p_id=stripslashes($arr[$i][$m]); $my_t_id=stripslashes($arr[$i][$m]); #Execute the statement $insert_t_stmt->execute( ) or die ($insert_t_stmt->error); $insert_t_stmt->bind_result($Entryerr); while ($insert_strat_stmt->fetch( )) { $error12=$Entryerr; if(substr($error12,0, 4)=="succ"){$suc=$error12;} } }//inner for } $insert_t_stmt->close( ); $mysqli->close( );
  15. I have this stored procedure below.how can i excute itt using php to insert data from an array like this one: Array ( [Japanese] => Array ( [hot] => wasabi [salty] => soy sauce [sweety] => soy rdsauce [bitter] => pepper sauce ) [Chinese] => Array ( [hot] => wasabi [salty] => soy sauce [sweety] => soy rdsauce_one [bitter] => pepper sauce3 ) [indian] => Array ( [hot] => wasabi [salty] => soy sauce [sweety] => soy rdsauce [bitter] => pepper sauce4 ) [mexican] => Array ( [hot] => soanzo [salty] => soy sauce1 [sweety] => soy sauceeur [bitter] => pepper sauce_sausage ) [russian] => Array ( [hot] => soanzo [salty] => soy sauce1 [sweety] => soy sauceeur [bitter] => pepper sauce_pork ) [ganda] => Array ( [hot] => soanzo [salty] => soy sauce1 [sweety] => soy sauce_beef [bitter] => luwombo_chicken ) ) DROP PROCEDURE IF EXISTS sp_addnewstratplandetails $$ CREATE PROCEDURE sp_addnewstratplandetails(IN in_stratprio_id int,IN in_Plalt varchar(255),in in_Out varchar(255),in in_Actes varchar(255),in in_performars varchar(255),in in_tar varchar(255),in in_state int) MODIFIES SQL DATA BEGIN DECLARE Result1 int; DECLARE pcnt1 int; DECLARE o_id varchar(255);DECLARE in_Outrids varchar(255); DECLARE in_actids varchar(255);DECLARE in_pids varchar(255); DECLARE r_id varchar(255); DECLARE in_PLANrids varchar(255); DECLARE pcnt int; DECLARE a_id varchar(255); DECLARE pcntI int; DECLARE p_id varchar(255);DECLARE in_tids varchar(255); DECLARE pcntt int; DECLARE pchk int; DECLARE lo_id int; DECLARE l_AO_id int; DECLARE l_perfo_id int; DECLARE l_tar_id int; DECLARE t_id varchar(255); DECLARE in_Pllt_id varchar(20); DECLARE l_out_id varchar(20); DECLARE l_Actes_id varchar(20); DECLARE l_pers_id varchar(20); DECLARE l_tar_id varchar(20); DECLARE exit handler for sqlexception BEGIN /* ERROR*/ ROLLBACK; SELECT CONCAT('Error occurred – Record not saved!')as "Result"; END; DECLARE exit handler for sqlwarning BEGIN /* WARNING*/ ROLLBACK; SELECT CONCAT('Error:Record not saved already Exists! ') as "Result"; END; START TRANSACTION; /*check if plad result exists*/ SELECT count(*) into Result1 FROM _Plantstbl WHERE Plannult=in_Plalt and EXISTS (SELECT * FROM _stratbl WHERE _Plantstbl.PlannedResult_id=_stratbl.Plannult_id and stratprio_id=in_stratprio_id); IF Result1=0 && in_state=0 THEN SELECT count(*) into pcnt from _Plantstbl where Plannult_id like concat(in_stratprio_id,'%'); SET r_id=pcnt+1; SET in_PLANrids=concat(in_stratprio_id,'.',r_id); INSERT INTO _Plantstbl(Plannult_id,Plannsult) VALUES(in_PLANrids,in_Plalt); ELSE UPDATE _Plantstbl SET Plannsult=in_Plalt WHERE PlannedResult=in_Plalt; END IF; SELECT Plannult_id into in_Pllt_id FROM _Plantstbl WHERE Plannsult=in_Plalt ; SELECT count(*) into lo_id FROM Out_tbl WHERE outcome=in_Out ; IF lo_id=0 THEN SELECT count(*) into pcnt1 from Out_tbl where out_id like concat(in_Pllt_id,'.','%'); SET o_id=pcnt1+1; SET in_Outrids=concat(in_Pllt_id,'.',o_id); INSERT INTO Out_tbl(out_id,outme) VALUES(in_Outrids,in_Out); ELSE UPDATE Out_tbl SET outcome=in_Out WHERE outcome=in_Out ; END IF; SELECT count(*) into l_AO_id FROM _Plastbl WHERE Actes=in_Actes; IF l_AO_id=0 THEN SELECT out_id into l_out_id FROM Out_tbl WHERE outcome=in_Out ; SELECT count(*) into pcnt from _Plastbl where Actes_id like concat(l_out_id,'.','%'); SET a_id=pcnt+1; SET in_actids=concat(l_out_id,'.',a_id); INSERT INTO _Plastbl(Actes_id,Actes) VALUES(in_actids,in_Actes); ELSE UPDATE _Plastbl SET Actes=in_Actes WHERE Actes=in_Actes ; END IF; SELECT count(*) into l_perfo_id FROM _Pertbl WHERE perfors=in_performars; IF l_perfo_id=0 THEN SELECT count(*) into pcntI from _Pertbl where Pind_id like concat(l_out_id,'.','%'); SET p_id=pcntI+1; SET in_pids=concat(l_out_id,'.',p_id); INSERT INTO _Pertbl(Pind_id,perfors) VALUES(in_pids,in_performars); ELSE UPDATE _Pertbl SET perfors=in_performars WHERE perfors=in_performars; END IF; SELECT count(*) into l_tar_id FROM _Ttbl WHERE tar=in_tar; IF l_tar_id=0 THEN SELECT count(*) into pcntt from _Ttbl where tar_id like concat(l_out_id,'.','%'); SET t_id=pcntt+1; SET in_tids=concat(l_out_id,'.',t_id); INSERT INTO _Ttbl(tar_id,tar) VALUES(in_tids,in_tar); ELSE UPDATE _Ttbl SET tar=in_tar WHERE tar=in_tar; END IF; COMMIT; SELECT Actes_id into l_Actes_id FROM _Plastbl WHERE Actes=in_Actes; SELECT Pind_id into l_pers_id FROM _Pertbl WHERE perfors=in_performars; SELECT tar_id into l_tar_id FROM _Ttbl WHERE tar=in_tar; INSERT INTO _stratbl(stratprio_id,Plesult_id,out_id,Actes_id,Pind_id,tar_id ) VALUES(in_stratprio_id,in_Pllt_id,l_out_id,l_Actes_id,l_pers_id ,l_tar_id); SELECT 'success '; END$$ DELIMITER ;
  16. $flavors[]= array('Japanese' => array('hot' => 'wasabi','salty' => 'soy sauce','sweety' => 'soy rdsauce','bitter' => 'pepper sauce'), 'Chinese' => array('hot' => '','salty' => '','sweety' => 'soy rdsauce_one','bitter' => 'pepper sauce3'), 'indian' => array('hot' => '','salty' => '','sweety' => '','bitter' => 'pepper sauce4'), 'mexican' => array('hot' => 'soanzo','salty' => 'soy sauce1','sweety' => 'soy sauceeur','bitter' => 'pepper sauce_sausage'), 'russian' => array('hot' => '','salty' => '','sweety' => '','bitter' => 'pepper sauce_pork'),'ganda' => array('hot' => '', 'salty' => '','sweety' => 'soy sauce_beef','bitter' => 'luwombo_chicken')); can you make it work for such an array. such that the empty values are filled with the content of the previous full array closest to it. say for ganda, it shpul be filled with the mexican values corresponding to each empty value, this is true for russian too. And the same setting has to be applied to those next to the full japanese array. the final array should be like this.keeping in mind that it can be bigger than this. Array ( [Japanese] => Array ( [hot] => wasabi [salty] => soy sauce [sweety] => soy rdsauce [bitter] => pepper sauce ) [Chinese] => Array ( [hot] => wasabi [salty] => soy sauce [sweety] => soy rdsauce_one [bitter] => pepper sauce3 ) [indian] => Array ( [hot] => wasabi [salty] => soy sauce [sweety] => soy rdsauce [bitter] => pepper sauce4 ) [mexican] => Array ( [hot] => soanzo [salty] => soy sauce1 [sweety] => soy sauceeur [bitter] => pepper sauce_sausage ) [russian] => Array ( [hot] => soanzo [salty] => soy sauce1 [sweety] => soy sauceeur [bitter] => pepper sauce_pork ) [ganda] => Array ( [hot] => soanzo [salty] => soy sauce1 [sweety] => soy sauce_beef [bitter] => luwombo_chicken ) )
  17. i have this array: $flavors = array('Japanese' => array('hot' => 'wasabi', 'salty' => 'soy sauce'), 'Chinese' => array('hot' => '', 'pepper-salty' => 'prickly ash'),'indian' => array('hot' => '', 'pepper-salty' => 'prickly ash'),'mexican' => array('hot' => 'soanzo', 'salty' => 'soy sauce'), 'russian' => array('hot' => '', 'pepper-salty' => 'prickly ash'),'ganda' => array('hot' => '', 'pepper-salty' => 'prickly ash')); how can i loop through it and replace the empty values with the value of the previously filled part of say japanese ' hot for the two arrays next to it and mexican' soanzo for the next two to it using for loop
  18. iam trying to get data from many input fields in a table based on their column position.they are also named based on their column position.. if in the next column the input is empty, i should be able to track the previously full input and place its value instead. but so far it is always returning empty . where am going wrong with my code below $d=0; $arr=array(); while($d<$_POST['total']){ $d++; if($_POST['outcome'.$d]!==""){ $out=$_POST['outcome'.$d]; $act=$_POST['activity'.$d]; $ind=$_POST['indicator'.$d]; $tar=$_POST['target'.$d]; }else if($_POST['outcome'.$d]==""&& $_POST['activity'.$d]!==""){//$pos=$d #get the previously filled input for($fulo=$d;$fulo>0;$fulo--){ if($_POST['outcome'.$fulo] !==""){ $out=$_POST['outcome'.$fulo];break; }else{continue;} } $act=$_POST['activity'.$d]; $ind=$_POST['indicator'.$d]; $tar=$_POST['target'.$d]; } //} $arr[]= array($out,$act,$ind,$tar ); }
  19. How can i multi-execute such a stored procedure with a transaction inside it on a single Mysqli connection in php.
  20. my stored procedure worked on the mysql commandline .Ithink the problem could be with the execution of the transaction inside the stored procedure .how can I do that using php .that is where i have failed even when that space is removed
  21. $l_planid should be $l_pla.here is the code for my stored proc it has a transaction in it and populating many different tables: DELIMITER $$ DROP PROCEDURE IF EXISTS sp_addnewdata $$ CREATE PROCEDURE sp_addnewdata(IN in_stratprio int,IN in_Planre varchar(255),in in_Outcomes varchar(255),in in_Activities varchar(255),in in_performa varchar(255),in in_tar1 varchar(255),in in_state int) MODIFIES SQL DATA BEGIN DECLARE Result1 int; DECLARE pcnt1 int; DECLARE o_id varchar(255);DECLARE in_Outcomesrids varchar(255); DECLARE in_actids varchar(255);DECLARE in_pids varchar(255); DECLARE r_id varchar(255); DECLARE in_PLANrids varchar(255); DECLARE pcnt int; DECLARE a_id varchar(255); DECLARE pcntI int; DECLARE p_id varchar(255);DECLARE in_tids varchar(255); DECLARE pcntt int; DECLARE pchk int; DECLARE lo_id int; DECLARE l_AO_id int; DECLARE l_perfo_id int; DECLARE l_tar_id int; DECLARE t_id varchar(255); DECLARE in_Planid varchar(20); DECLARE l_outcome_id varchar(20); DECLARE l_Activit varchar(20); DECLARE l_perform varchar(20); DECLARE l_tar varchar(20); START TRANSACTION; SAVEPOINT savepoint_tfer; /*check if planned result exists*/ SELECT count(*) into Result1 FROM Plantbl WHERE Planre=in_Planre and EXISTS (SELECT * FROM _strate WHERE Plantbl.Planid=_strate.Planid and stratprio_id=in_stratprio); IF Result1=0 && in_state=0 THEN SELECT count(*) into pcnt from Plantbl where Planid like concat(in_stratprio,'%'); SET r_id=pcnt+1; SET in_PLANrids=concat(in_stratprio,'.',r_id); INSERT INTO Plantbl(Planid,Planre) VALUES(in_PLANrids,in_Planre); END IF; SELECT Planid into in_Planid FROM Plantbl WHERE Planre=in_Planre ; SELECT count(*) into lo_id FROM Out_tbl WHERE outcome=in_Outcomes ; IF lo_id=0 THEN SELECT count(*) into pcnt1 from Out_tbl where outcome_id like concat(in_Planid,'.','%'); SET o_id=pcnt1+1; SET in_Outcomesrids=concat(in_Planid,'.',o_id); INSERT INTO Out_tbl(outcome_id,outcome) VALUES(in_Outcomesrids,in_Outcomes); ELSE ROLLBACK TO savepoint_tfer; END IF; SELECT count(*) into l_AO_id FROM _Planresdetailstbl WHERE Activities=in_Activities; IF l_AO_id=0 THEN SELECT outcome_id into l_outcome_id FROM Out_tbl WHERE outcome=in_Outcomes ; SELECT count(*) into pcnt from _Planresdetailstbl where Activities_id like concat(l_outcome_id,'.','%'); SET a_id=pcnt+1; SET in_actids=concat(l_outcome_id,'.',a_id); INSERT INTO _Planresdetailstbl(Activities_id,Activities) VALUES(in_actids,in_Activities); ELSE ROLLBACK TO savepoint_tfer; END IF; SELECT count(*) into l_perfo_id FROM _Perforailstbl WHERE performance_Indicators=in_performa; IF l_perfo_id=0 THEN SELECT count(*) into pcntI from _Perforailstbl where Pind_id like concat(l_outcome_id,'.','%'); SET p_id=pcntI+1; SET in_pids=concat(l_outcome_id,'.',p_id); INSERT INTO _Perforailstbl(Pind_id,performanc e_Indicators) VALUES(in_pids,in_performa); ELSE ROLLBACK TO savepoint_tfer; END IF; SELECT count(*) into l_tar_id FROM tartbl WHERE tar1=in_tar1; IF l_tar_id=0 THEN SELECT count(*) into pcntt from tartbl where tar like concat(l_outcome_id,'.','%'); SET t_id=pcntt+1; SET in_tids=concat(l_outcome_id,'.',t_id); INSERT INTO tartbl(tar,tar1) VALUES(in_tids,in_tar1); ELSE ROLLBACK TO savepoint_tfer; END IF; COMMIT; SELECT Activities_id into l_Activit FROM _Planresdetailstbl WHERE Activities=in_Activities; SELECT Pind_id into l_perform FROM _Perforailstbl WHERE performance_Indicators=in_performa; SELECT tar into l_tar FROM tartbl WHERE tar1=in_tar1; INSERT INTO _stbl(stratprio_id,Planid,outcome_id,Activities_id ,Pind_id,tar ) VALUES(in_stratprio,in_Plan_id,l_outcome_id,l_A cti_id,l_perf_id ,l_tar_id); END$$ DELIMITER ; I get no error from php by the fact that nothing is added to the database though no error msg is displayed
  22. hello, i have this php 2D array:$arr[]= array($pri,$l_pla,$my_o,$my_Ac,$my_p,$my_t); and would like to insert all its contents into a databse using php. include("config.php"); for ($j = 0, $num_specials = count($arr); $j < $num_specials; $j++) { // $num_sub is 3: the number of elements in each sub-array for ($m = 0, $num_sub = count($arr[$j]); $m < $num_sub; $m++) { //print "Element [$j][$m] is " . $arr[$j][$m] . "\n" $strat_sql="call sp_addnewdata(?,?,?,?,?,?,?)"; $insert=$mysqli->prepare($strat_sql)or die($mysqli->error); #associate variables with the input parameters $insert->bind_param("isssssi",$pri,$l_pla,$my_o,$my_Ac,$my _p,$my_t,$snew); $pri =$arr[$j][$m]; $l_pla=$arr[$j][$m]; if($j>=1){$snew=1;}else{$snew=$l_planid;} //save record $my_o=$arr[$j][$m]; $my_Ac=$arr[$j][$m]; $my_p=$arr[$j][$m]; $my_t=$arr[$j][$m]; #Execute the statement $insert->execute( ) or die ($insert->error); $insert->close( ); //$mysqli->close( ); } } It has failed so far.The stored procedure works well on the mysql.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.